DroidKaigi / conference-app-2018

The Official Conference App for DroidKaigi 2018 Tokyo
Apache License 2.0
1.35k stars 332 forks source link

Use top level function instead of companion object. #556

Closed satorufujiwara closed 6 years ago

satorufujiwara commented 6 years ago

Issue

Overview (Required)

Changes

These are decompiled java code.

Before

public final class AppInjector {
   public static final AppInjector.Companion Companion = new AppInjector.Companion((DefaultConstructorMarker)null);

   public static final class Companion {
      public final void init(@NotNull App app) {
         Intrinsics.checkParameterIsNotNull(app, "app");
         DaggerAppComponent.builder().application((Application)app).networkModule(NetworkModule.Companion.getInstance()).databaseModule(DatabaseModule.Companion.getInstance()).build().inject(app);
         app.registerActivityLifecycleCallbacks((ActivityLifecycleCallbacks)(new ActivityLifecycleCallbacks() {
            public void onActivityCreated(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
               Intrinsics.checkParameterIsNotNull(activity, "activity");
               AppInjector.Companion.handleActivity(activity);
            }

            public void onActivityStarted(@NotNull Activity activity) {
               Intrinsics.checkParameterIsNotNull(activity, "activity");
            }

            public void onActivityResumed(@NotNull Activity activity) {
               Intrinsics.checkParameterIsNotNull(activity, "activity");
            }

            public void onActivityPaused(@NotNull Activity activity) {
               Intrinsics.checkParameterIsNotNull(activity, "activity");
            }

            public void onActivityStopped(@NotNull Activity activity) {
               Intrinsics.checkParameterIsNotNull(activity, "activity");
            }

            public void onActivitySaveInstanceState(@NotNull Activity activity, @Nullable Bundle outState) {
               Intrinsics.checkParameterIsNotNull(activity, "activity");
            }

            public void onActivityDestroyed(@NotNull Activity activity) {
               Intrinsics.checkParameterIsNotNull(activity, "activity");
            }
         }));
      }

      private final void handleActivity(Activity activity) {
         if(activity instanceof HasSupportFragmentInjector) {
            AndroidInjection.inject(activity);
         }

         Activity var10000 = activity;
         if(!(activity instanceof FragmentActivity)) {
            var10000 = null;
         }

         FragmentActivity fragmentActivity = (FragmentActivity)var10000;
         if(fragmentActivity != null) {
            FragmentManager var3 = fragmentActivity.getSupportFragmentManager();
            if(var3 != null) {
               var3.registerFragmentLifecycleCallbacks((FragmentLifecycleCallbacks)(new FragmentLifecycleCallbacks() {
                  public void onFragmentCreated(@Nullable FragmentManager fm, @Nullable Fragment f, @Nullable Bundle savedInstanceState) {
                     if(f instanceof Injectable) {
                        AndroidSupportInjection.inject(f);
                     }

                  }
               }), true);
            }
         }

      }

      private Companion() {
      }

      // $FF: synthetic method
      public Companion(DefaultConstructorMarker $constructor_marker) {
         this();
      }
   }
}

After

public final class AppInjectorKt {
   public static final void initDaggerComponent(@NotNull App $receiver) {
      Intrinsics.checkParameterIsNotNull($receiver, "$receiver");
      DaggerAppComponent.builder().application((Application)$receiver).networkModule(NetworkModule.Companion.getInstance()).databaseModule(DatabaseModule.Companion.getInstance()).build().inject($receiver);
      $receiver.registerActivityLifecycleCallbacks((ActivityLifecycleCallbacks)(new ActivityLifecycleCallbacks() {
         public void onActivityCreated(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
            Intrinsics.checkParameterIsNotNull(activity, "activity");
            AppInjectorKt.handleActivity(activity);
         }

         public void onActivityStarted(@NotNull Activity activity) {
            Intrinsics.checkParameterIsNotNull(activity, "activity");
         }

         public void onActivityResumed(@NotNull Activity activity) {
            Intrinsics.checkParameterIsNotNull(activity, "activity");
         }

         public void onActivityPaused(@NotNull Activity activity) {
            Intrinsics.checkParameterIsNotNull(activity, "activity");
         }

         public void onActivityStopped(@NotNull Activity activity) {
            Intrinsics.checkParameterIsNotNull(activity, "activity");
         }

         public void onActivitySaveInstanceState(@NotNull Activity activity, @Nullable Bundle outState) {
            Intrinsics.checkParameterIsNotNull(activity, "activity");
         }

         public void onActivityDestroyed(@NotNull Activity activity) {
            Intrinsics.checkParameterIsNotNull(activity, "activity");
         }
      }));
   }

   private static final void handleActivity(Activity activity) {
      if(activity instanceof HasSupportFragmentInjector) {
         AndroidInjection.inject(activity);
      }

      Activity var10000 = activity;
      if(!(activity instanceof FragmentActivity)) {
         var10000 = null;
      }

      FragmentActivity fragmentActivity = (FragmentActivity)var10000;
      if(fragmentActivity != null) {
         FragmentManager var2 = fragmentActivity.getSupportFragmentManager();
         if(var2 != null) {
            var2.registerFragmentLifecycleCallbacks((FragmentLifecycleCallbacks)(new FragmentLifecycleCallbacks() {
               public void onFragmentCreated(@Nullable FragmentManager fm, @Nullable Fragment f, @Nullable Bundle savedInstanceState) {
                  if(f instanceof Injectable) {
                     AndroidSupportInjection.inject(f);
                  }

               }
            }), true);
         }
      }

   }
}

Links

Screenshot

takahirom commented 6 years ago

:eyes:

takahirom commented 6 years ago

Thank you for deleting useless instances! LGTM 🥇

takahirom commented 6 years ago

I listen with this just interesting, do you think that it is better to replace it with the top level function in this case too? 🤔 https://github.com/DroidKaigi/conference-app-2018/blob/master/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/common/notification/NotificationHelper.kt

takahirom commented 6 years ago

anyway merged! 👍