-
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 PostsListAdapter #7989
Changes from 1 commit
0a68bc3
c627dc5
d054ebf
b405674
4403677
2129142
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,14 @@ class ImageManager @Inject constructor(val placeholderManager: ImagePlaceholderM | |
.into(imageView) | ||
} | ||
|
||
@JvmOverloads | ||
fun load(imageView: ImageView, resourceId: Int, scaleType: ImageView.ScaleType = CENTER) { | ||
GlideApp.with(imageView.context) | ||
.load(resourceId) | ||
.applyScaleType(scaleType) | ||
.into(imageView) | ||
} | ||
|
||
fun loadIntoCircle(imageView: ImageView, imageType: ImageType, imgUrl: String) { | ||
GlideApp.with(imageView.context) | ||
.load(imgUrl) | ||
|
@@ -121,6 +129,15 @@ class ImageManager @Inject constructor(val placeholderManager: ImagePlaceholderM | |
ImageManager(ImagePlaceholderManager()).load(imageView, drawable, scaleType) | ||
} | ||
|
||
@JvmStatic | ||
@Deprecated("Use injected ImageManager", | ||
ReplaceWith("imageManager.load(imageView, resourceId, scaleType)", | ||
"org.wordpress.android.util.image.ImageManager")) | ||
@JvmOverloads | ||
fun loadImage(imageView: ImageView, resourceId: Int, scaleType: ImageView.ScaleType = CENTER) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method doesn't seem to be used, am I missing something? Adding a deprecated, unused method feels really weird to me. I am not familiar with the history of the project, could you let me know why we needed to add these deprecated methods in the first place? Actually, I just checked and none of them seems to be used. We have this comment I am really confused. I have a few more questions, but I'll wait until I understand a bit more about what's going on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are basically two related reasons for introducing deprecated methods
Since we want everyone to be able to use the ImageManager without the need for huge refactoring, I believe it should provide static methods. On the other hand we want to make sure no-one uses the static methods when they can use Dagger, hence the methods are deprecated. Let me know if you have any further questions or if you believe I should take another approach:). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the problem is that these deprecated methods are not currently in use (at least in this branch). Until they are actually needed, I'd strongly advice against adding them. I can't find our documentation for it, but I know that we don't want any unused code in our repositories. If they are actually in use and I am just missing it, please let me know. Specifically for this case, adding that code right now compared to adding that code when it's needed, it makes it not a part of the correct PR review. I can't comment on that code at all right now, because I don't know how it's going to be used. However, if that deprecated method was added in a PR that uses it and there is a better way to do it without the need of the deprecated method, I can say that let's not add it and do this alternative way instead. Does that make sense? Side note: For the deprecated methods, creating a new instance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have always been a fan of no dead/unused code rule and I think every company should have such rule. On the other hand every rule has valid exceptions. I believe this is a case where it makes sense to make an exception.
Probably the biggest advantage of implementing the methods before they are actually used comes when more people are working on the refactoring. It prevents everyone from creating their own version of such method. Since I'm the only one working on this, I'm okay with removing all the unused methods. However, I'd like to hear another opinion on this topic, so when we work on refactoring in a group I know whether it's a valid approach or not. @hypest Your comments are always wise. Could you please give us your opinion on this? Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Tbh I can't think of any other way -> we could let the client create an instance of the ImageManager and send it to the method, but it wouldn't make sense to have static methods in the first place (the client could directly call the instance methods). Disadvantage of calling instance methods on a manually created instance is, that those methods are not Deprecated. I guess I could create a lazy loaded singleton, but it feels like overkill. The ImageManager is basically just an Object with few extra methods. It's creation and memory footprint should be neglectable. Moreover current garbage collection techniques are optimized for collecting many short-lived objects so the memory footprint might be actually lower than creating one longer living object. There are several great articles about this topic (for instance here and here). Nevertheless, I'll be happy to rewrite it. Do you have any specific suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for pinging @malinajirka !
So, it seems there is a usage for one of the static methods. I guess it would help to merge
The companion object is effectively a utility class and since it's not part of an actual library, the incentive to cater for the needs of a random user of the lib is low I think. In this case, and since this was brought up during the review, I'd be leaning towards cleaning up the companion object, only leaving in the static method that is actually used. I'd expect any future static method additions to the companion object to "copy" the one method already defined and mark it as I'd also advocate that even if there are good (potential) uses the static methods, we'd still like to "push" for using the DI'ed singleton instead. With that in mind, offering a complete set of static methods like currently in the PR would enable people to use them, beating the purpose of "pushing" to DI :) All in all, I think the utility of the static methods is minimal at the moment and we can easily handle adding more in the future if needed so, I'd recommend not offering unused methods in this PR. Hope I helped! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you both;), I'm going to clean it up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @malinajirka Is there a reason you don't just add a method like |
||
ImageManager(ImagePlaceholderManager()).load(imageView, resourceId, scaleType) | ||
} | ||
|
||
@JvmStatic | ||
@Deprecated("Use injected ImageManager", | ||
ReplaceWith("imageManager.loadIntoCircle(imageView, imgType, imgUrl)", | ||
|
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.
Same comment as this one