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

[android] Remove Android Studio warnings #8073

Merged
merged 1 commit into from
May 3, 2024

Conversation

Jean-BaptisteC
Copy link
Member

@Jean-BaptisteC Jean-BaptisteC commented May 3, 2024

This PR fixes some Android Studio warnings:

  • Remove unused imports
  • Replace StringBuilder with String
  • Use lambda
  • Replace .size == 0 by isEmpty()
  • Remove useless semicolons
  • Remove redundant type
  • Use final on variables when possible

@@ -406,11 +406,10 @@ void bind(@NonNull SectionPosition position,
final long trackId = sectionsDataSource.getTrackId(position);
Track track = BookmarkManager.INSTANCE.getTrack(trackId);
mName.setText(track.getName());
mDistance.setText(new StringBuilder().append(mDistance.getContext()
Copy link
Member

Choose a reason for hiding this comment

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

  1. Was it done deliberately to speed up the code? Is there any comment in git blame?
  2. Does it make sense to cache .getString(R.string.length) result here and maybe in some other places, where it is called repeatedly for many objects?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing in git blame
It's the only place using .getString(R.string.length)

@@ -105,17 +105,15 @@ public String getDescription()
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder("BookmarkCategory{");
sb.append("mId=").append(mId);
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that the nee code is faster? Is there any documentation or benchmark about it?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right
In the most of case, StringBuilder is more efficient -> https://dip-mazumder.medium.com/stringbuilder-vs-string-in-java-a-guide-for-optimal-memory-usage-4a284d8243ea
I have reverted changes about StringBuilder

@@ -102,8 +103,7 @@ private FeatureCategory[] makeFeatureCategoriesFromTypes(@NonNull String[] creat
categories[i] = new FeatureCategory(creatableTypes[i], localizedType);
}

Arrays.sort(categories, (lhs, rhs) ->
lhs.getLocalizedTypeName().compareTo(rhs.getLocalizedTypeName()));
Arrays.sort(categories, Comparator.comparing(FeatureCategory::getLocalizedTypeName));
Copy link
Member

Choose a reason for hiding this comment

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

Curious, why is it better?

Signed-off-by: Jean-BaptisteC <jeanbaptiste.charron@outlook.fr>
Copy link
Member

@biodranik biodranik left a comment

Choose a reason for hiding this comment

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

Thanks!

@biodranik biodranik merged commit d5e4779 into organicmaps:master May 3, 2024
6 checks passed
@Jean-BaptisteC Jean-BaptisteC deleted the rm_warnings branch May 3, 2024 20:15
final DialogInterface.OnClickListener navigateToLoginHandler = (DialogInterface dialog, int which) -> {
startActivity(new Intent(MwmActivity.this, OsmLoginActivity.class));
};
final DialogInterface.OnClickListener navigateToLoginHandler = (DialogInterface dialog, int which) -> startActivity(new Intent(MwmActivity.this, OsmLoginActivity.class));
Copy link
Member

Choose a reason for hiding this comment

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

final DialogInterface.OnClickListener navigateToLoginHandler = (dialog, which) -> startActivity(new Intent(MwmActivity.this, OsmLoginActivity.class));

or

final DialogInterface.OnClickListener navigateToLoginHandler = (_, _) -> startActivity(new Intent(MwmActivity.this, OsmLoginActivity.class));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants