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

Bump gradle version #79

Merged
merged 16 commits into from Apr 25, 2017
Merged

Bump gradle version #79

merged 16 commits into from Apr 25, 2017

Conversation

coryroy
Copy link
Contributor

@coryroy coryroy commented Apr 11, 2017

what

Originally the plan was simply to bump version of gradle to 2.3.1 and gradle wrapper to 3.3

This had some fall on effects as we were relying on:
fragmentManager.getFragments()

but this with the new gradle version this not shows correctly as hidden so we had to come up with another solution.

how

Keeping a static HashMap of the fragments by adapter position:

private static Map<Integer, DiscoveryFragment> fragmentMap;

seems to work very well. WeakReferences were tried but it seemed to cause many problems with fragments disappearing on config changes.

Some important things with the implementation:

/**
  * Don't pull directly from the map as it may be null
  */
  private @NonNull DiscoveryFragment safeGetFragment(final int position) {
    DiscoveryFragment fragment = fragmentMap.get(position);
    if (fragment == null) {
      fragment = getItem(position);
    }

    return fragment;
  }

and also in the constructor for the adapter:

if (fragmentMap == null) {
  fragmentMap = new HashMap<>();
}

If you don't do the null check the map will get wiped out on rotate etc which you don't want as the fragments themselves are still around.

@coryroy coryroy requested a review from luoser April 11, 2017 22:36
@mbrandonw
Copy link
Contributor

7974012-116640902_17-s4-v1

Copy link
Contributor

@luoser luoser left a comment

Choose a reason for hiding this comment

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

welcome 😎

@luoser
Copy link
Contributor

luoser commented Apr 11, 2017

oooh interesting, some lint failures with these gradle changes. we're gonna look into these tomorrow a.m. before merging

@coryroy
Copy link
Contributor Author

coryroy commented Apr 12, 2017

I pushed a new commit to the branch. Now inheriting from AppCompatTextView in accordance with lint.

@coryroy coryroy requested a review from mbrandonw April 12, 2017 13:31
Copy link
Contributor

@mbrandonw mbrandonw left a comment

Choose a reason for hiding this comment

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

Nice nice!

Regarding that unused import. I remember Android Studio having a setting to automatically strip unused imports (at least mine does). Worth turning that on, and wondering if we can share that setting across all native engineers.

@coryroy
Copy link
Contributor Author

coryroy commented Apr 12, 2017

second lint issue is going to be a larger problem:
https://code.google.com/p/android/issues/detail?id=234673

Looks like this method is marked as hidden in the support api!

Copy link
Contributor

@mbrandonw mbrandonw left a comment

Choose a reason for hiding this comment

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

just a few comments.

btw not sure if lisa has shown you this yet, but you can run all of the linting and checkstyle stuff locally by doing milkrun quality.

return DiscoveryFragment.newInstance(position);
public
@NonNull
Fragment getItem(final int position) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we keep all of the modifiers in the same line of the function.

did something in our check style say to do this?

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like something android studio does automatically when auto-completing override methods, cory and i are gonna pair this morning and i'll explain our code style!

return fragmentPosition == position;
})
.subscribe(frag -> frag.takeCategories(categories));
fragmentMap.get(position).takeCategories(categories);
Copy link
Contributor

Choose a reason for hiding this comment

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

sooooooooo much better!

public
@NonNull
Fragment getItem(final int position) {
DiscoveryFragment fragment = DiscoveryFragment.newInstance(position);
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like check style wants this to be final. we like to final all the things

@coryroy
Copy link
Contributor Author

coryroy commented Apr 13, 2017

This build is still failing during :app:lintExternalPre21Release, but the lint file isn't even created. I think it's crashing during lint!

bitmoji

@mbrandonw
Copy link
Contributor

This build is still failing during :app:lintExternalPre21Release, but the lint file isn't even created. I think it's crashing during lint!

@coryroy according to the lint output it's pointing at this line:

pages.stream().forEach(page -> fragmentMap.get(page).clearPage());

I didn't catch this initially, but this isn't valid java 6 code because it's using java 8 features. we need to change this to the old school way.


public final class DiscoveryPagerAdapter extends FragmentPagerAdapter {
private final Delegate delegate;
private final FragmentManager fragmentManager;
private List<String> pageTitles;
private Map<Integer, DiscoveryFragment> fragmentMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

Main question I have here is whether there are any issues with holding onto a reference to these fragments – can it potentially cause any issues with GC? I couldn't see a clear explanation on how this works from a scan of the docs, so would just hope that we have confidence that this would not cause issues with destroying fragments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@christopherwright Good point. Do you think putting weak references in the map would be a better idea.

luoser
luoser previously requested changes Apr 17, 2017
Copy link
Contributor

@luoser luoser left a comment

Choose a reason for hiding this comment

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

just a few things

.gitignore Outdated
@@ -27,8 +27,14 @@ proguard/
# Log Files
*.log

# OSX files
# OS generated files #
######################
Copy link
Contributor

Choose a reason for hiding this comment

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

think we should cut out this comment line, to match the rest of this file's style

.gitignore Outdated
.DS_Store
.DS_Store?
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason why there's a ? appended?

@@ -40,8 +38,11 @@ public void setPrimaryItem(final @NonNull ViewGroup container, final int positio
}

@Override
public @NonNull Fragment getItem(final int position) {
return DiscoveryFragment.newInstance(position);
@NonNull
Copy link
Contributor

Choose a reason for hiding this comment

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

in general, we put our nullability annotations right in front of the type which it is annotating, i.e.

public @NonNull DiscoveryFragment

i'll update our styleguide to include this, since it's something we discussed a while ago as a team but neglected to include in the styleguide!

@@ -44,7 +43,8 @@

public DiscoveryFragment() {}

public static @NonNull Fragment newInstance(final int position) {
@NonNull
Copy link
Contributor

Choose a reason for hiding this comment

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

same here with @NonNull

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the auto-formatter messed this up as I didn't specifically change this. Is it possible to change the settings file so this doesn't happen on auto-format?

@mbrandonw mbrandonw dismissed their stale review April 18, 2017 18:35

Dismissing my review as I will defer to @luoser for her final approval!

@luoser luoser dismissed their stale review April 25, 2017 22:34

merged in some related changes, feedback is now addressed

@luoser
Copy link
Contributor

luoser commented Apr 25, 2017

alrighty, we're ready to rock n roll. for anyone on an older version of Android Studio, be sure to upgrade to 2.3.1!

@luoser luoser merged commit 74a7b34 into master Apr 25, 2017
@luoser luoser deleted the upgrade_android_studio branch April 25, 2017 22:35
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

5 participants