From ff4f1766830cd0ab45ecd78ad9a813d6f95398cc Mon Sep 17 00:00:00 2001 From: gbalabaichkin Date: Wed, 15 Jun 2016 12:18:44 +0300 Subject: [PATCH 1/5] Support new event in fragment --- navi/src/main/java/com/trello/navi/Event.java | 9 ++++++++- .../java/com/trello/navi/component/NaviFragment.java | 6 ++++++ .../com/trello/navi/component/support/NaviFragment.java | 8 +++++++- .../main/java/com/trello/navi/internal/NaviEmitter.java | 7 +++++++ navi/src/test/java/com/trello/navi/NaviFragmentTest.java | 5 +++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/navi/src/main/java/com/trello/navi/Event.java b/navi/src/main/java/com/trello/navi/Event.java index 21c2c86..1fc6ae8 100644 --- a/navi/src/main/java/com/trello/navi/Event.java +++ b/navi/src/main/java/com/trello/navi/Event.java @@ -8,6 +8,7 @@ import android.os.Bundle; import android.os.PersistableBundle; import android.view.LayoutInflater; +import android.view.View; import android.view.ViewGroup; import com.trello.navi.model.ActivityResult; import com.trello.navi.model.BundleBundle; @@ -171,6 +172,11 @@ public final class Event { */ public static final Event DESTROY_VIEW = new Event<>(Type.DESTROY_VIEW, Void.class); + /** + * Emits {@link Fragment#onViewCreated(View, Bundle)} ()}. Emitted before super(). + */ + public static final Event VIEW_CREATED = new Event<>(Type.VIEW_CREATED, Bundle.class); + /** * Emits {@link Fragment#onDetach()}. Emitted before super(). */ @@ -245,6 +251,7 @@ public enum Type { ACTIVITY_CREATED, VIEW_STATE_RESTORED, DESTROY_VIEW, - DETACH + DETACH, + VIEW_CREATED } } diff --git a/navi/src/main/java/com/trello/navi/component/NaviFragment.java b/navi/src/main/java/com/trello/navi/component/NaviFragment.java index 37bf0c4..97bc685 100644 --- a/navi/src/main/java/com/trello/navi/component/NaviFragment.java +++ b/navi/src/main/java/com/trello/navi/component/NaviFragment.java @@ -119,4 +119,10 @@ public class NaviFragment extends Fragment implements NaviComponent { super.onRequestPermissionsResult(requestCode, permissions, grantResults); base.onRequestPermissionsResult(requestCode, permissions, grantResults); } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + base.onViewCreated(view, savedInstanceState); + super.onViewCreated(view, savedInstanceState); + } } diff --git a/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java b/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java index fda45b7..d8f011d 100644 --- a/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java +++ b/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java @@ -115,8 +115,14 @@ public class NaviFragment extends Fragment implements NaviComponent { } @Override @CallSuper public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, - @NonNull int[] grantResults) { + @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); base.onRequestPermissionsResult(requestCode, permissions, grantResults); } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + base.onViewCreated(view, savedInstanceState); + super.onViewCreated(view, savedInstanceState); + } } diff --git a/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java b/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java index 0f2315b..df13a7d 100644 --- a/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java +++ b/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java @@ -8,6 +8,9 @@ import android.os.Bundle; import android.os.PersistableBundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.View; + import com.trello.navi.Event; import com.trello.navi.Event.Type; import com.trello.navi.Listener; @@ -241,4 +244,8 @@ public void onStop() { public void onViewStateRestored(Bundle savedInstanceState) { emitEvent(Event.VIEW_STATE_RESTORED, savedInstanceState); } + + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + emitEvent(Event.VIEW_CREATED, savedInstanceState); + } } diff --git a/navi/src/test/java/com/trello/navi/NaviFragmentTest.java b/navi/src/test/java/com/trello/navi/NaviFragmentTest.java index 56a2f99..81a745b 100644 --- a/navi/src/test/java/com/trello/navi/NaviFragmentTest.java +++ b/navi/src/test/java/com/trello/navi/NaviFragmentTest.java @@ -295,4 +295,9 @@ public void restoreInstanceStatePersistableListener() { exception.expect(IllegalArgumentException.class); emitter.addListener(Event.DETACHED_FROM_WINDOW, mock(Listener.class)); } + + @Test public void onViewCreatedListener() { + exception.expect(IllegalArgumentException.class); + emitter.addListener(Event.VIEW_CREATED, mock(Listener.class)); + } } From ec2742e062fdcd5f23ec1680381d0fedf053f8f2 Mon Sep 17 00:00:00 2001 From: gbalabaichkin Date: Wed, 15 Jun 2016 16:49:56 +0300 Subject: [PATCH 2/5] Fixes and new tests --- navi/src/main/java/com/trello/navi/Event.java | 14 ++++++------- .../navi/component/NaviDialogFragment.java | 6 ++++++ .../trello/navi/component/NaviFragment.java | 12 +++++------ .../support/NaviAppCompatDialogFragment.java | 6 ++++++ .../navi/component/support/NaviFragment.java | 12 +++++------ .../trello/navi/internal/HandledEvents.java | 1 + .../com/trello/navi/internal/NaviEmitter.java | 8 +++---- .../com/trello/navi/NaviActivityTest.java | 5 +++++ .../com/trello/navi/NaviFragmentTest.java | 21 ++++++++++++++----- 9 files changed, 57 insertions(+), 28 deletions(-) diff --git a/navi/src/main/java/com/trello/navi/Event.java b/navi/src/main/java/com/trello/navi/Event.java index 1fc6ae8..e36b652 100644 --- a/navi/src/main/java/com/trello/navi/Event.java +++ b/navi/src/main/java/com/trello/navi/Event.java @@ -155,6 +155,11 @@ public final class Event { */ public static final Event CREATE_VIEW = new Event<>(Type.CREATE_VIEW, Bundle.class); + /** + * Emits {@link Fragment#onViewCreated(View, Bundle)} ()}. Emitted before super(). + */ + public static final Event VIEW_CREATED = new Event<>(Type.VIEW_CREATED, Bundle.class); + /** * Emits {@link Fragment#onActivityCreated(Bundle)}. Emitted after super(). */ @@ -172,11 +177,6 @@ public final class Event { */ public static final Event DESTROY_VIEW = new Event<>(Type.DESTROY_VIEW, Void.class); - /** - * Emits {@link Fragment#onViewCreated(View, Bundle)} ()}. Emitted before super(). - */ - public static final Event VIEW_CREATED = new Event<>(Type.VIEW_CREATED, Bundle.class); - /** * Emits {@link Fragment#onDetach()}. Emitted before super(). */ @@ -248,10 +248,10 @@ public enum Type { // Fragment-only ATTACH, CREATE_VIEW, + VIEW_CREATED, ACTIVITY_CREATED, VIEW_STATE_RESTORED, DESTROY_VIEW, - DETACH, - VIEW_CREATED + DETACH } } diff --git a/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java b/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java index cc4458b..de98093 100644 --- a/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java +++ b/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java @@ -54,6 +54,12 @@ public class NaviDialogFragment extends DialogFragment implements NaviComponent return super.onCreateView(inflater, container, savedInstanceState); } + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + base.onViewCreated(view, savedInstanceState); + super.onViewCreated(view, savedInstanceState); + } + @Override @CallSuper public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); base.onActivityCreated(savedInstanceState); diff --git a/navi/src/main/java/com/trello/navi/component/NaviFragment.java b/navi/src/main/java/com/trello/navi/component/NaviFragment.java index 97bc685..083eda4 100644 --- a/navi/src/main/java/com/trello/navi/component/NaviFragment.java +++ b/navi/src/main/java/com/trello/navi/component/NaviFragment.java @@ -54,6 +54,12 @@ public class NaviFragment extends Fragment implements NaviComponent { return super.onCreateView(inflater, container, savedInstanceState); } + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + base.onViewCreated(view, savedInstanceState); + super.onViewCreated(view, savedInstanceState); + } + @Override @CallSuper public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); base.onActivityCreated(savedInstanceState); @@ -119,10 +125,4 @@ public class NaviFragment extends Fragment implements NaviComponent { super.onRequestPermissionsResult(requestCode, permissions, grantResults); base.onRequestPermissionsResult(requestCode, permissions, grantResults); } - - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - base.onViewCreated(view, savedInstanceState); - super.onViewCreated(view, savedInstanceState); - } } diff --git a/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java b/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java index fd3535b..434bd92 100644 --- a/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java +++ b/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java @@ -54,6 +54,12 @@ public class NaviAppCompatDialogFragment extends DialogFragment implements NaviC return super.onCreateView(inflater, container, savedInstanceState); } + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + base.onViewCreated(view, savedInstanceState); + super.onViewCreated(view, savedInstanceState); + } + @Override @CallSuper public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); base.onActivityCreated(savedInstanceState); diff --git a/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java b/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java index d8f011d..98e202b 100644 --- a/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java +++ b/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java @@ -54,6 +54,12 @@ public class NaviFragment extends Fragment implements NaviComponent { return super.onCreateView(inflater, container, savedInstanceState); } + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + base.onViewCreated(view, savedInstanceState); + super.onViewCreated(view, savedInstanceState); + } + @Override @CallSuper public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); base.onActivityCreated(savedInstanceState); @@ -119,10 +125,4 @@ public class NaviFragment extends Fragment implements NaviComponent { super.onRequestPermissionsResult(requestCode, permissions, grantResults); base.onRequestPermissionsResult(requestCode, permissions, grantResults); } - - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - base.onViewCreated(view, savedInstanceState); - super.onViewCreated(view, savedInstanceState); - } } diff --git a/navi/src/main/java/com/trello/navi/internal/HandledEvents.java b/navi/src/main/java/com/trello/navi/internal/HandledEvents.java index 6bf470e..aca0d25 100644 --- a/navi/src/main/java/com/trello/navi/internal/HandledEvents.java +++ b/navi/src/main/java/com/trello/navi/internal/HandledEvents.java @@ -37,6 +37,7 @@ final class HandledEvents { Event.ATTACH, Event.CREATE, Event.CREATE_VIEW, + Event.VIEW_CREATED, Event.ACTIVITY_CREATED, Event.VIEW_STATE_RESTORED, Event.START, diff --git a/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java b/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java index df13a7d..42ca280 100644 --- a/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java +++ b/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java @@ -177,6 +177,10 @@ public void onCreateView(Bundle savedInstanceState) { emitEvent(Event.CREATE_VIEW, savedInstanceState); } + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + emitEvent(Event.VIEW_CREATED, savedInstanceState); + } + public void onDestroy() { emitEvent(Event.DESTROY); } @@ -244,8 +248,4 @@ public void onStop() { public void onViewStateRestored(Bundle savedInstanceState) { emitEvent(Event.VIEW_STATE_RESTORED, savedInstanceState); } - - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - emitEvent(Event.VIEW_CREATED, savedInstanceState); - } } diff --git a/navi/src/test/java/com/trello/navi/NaviActivityTest.java b/navi/src/test/java/com/trello/navi/NaviActivityTest.java index c55d72a..5ca1909 100644 --- a/navi/src/test/java/com/trello/navi/NaviActivityTest.java +++ b/navi/src/test/java/com/trello/navi/NaviActivityTest.java @@ -296,6 +296,11 @@ public final class NaviActivityTest { emitter.addListener(Event.CREATE_VIEW, mock(Listener.class)); } + @Test public void viewCreatedListener() { + exception.expect(IllegalArgumentException.class); + emitter.addListener(Event.VIEW_CREATED, mock(Listener.class)); + } + @Test public void activityCreatedListener() { exception.expect(IllegalArgumentException.class); emitter.addListener(Event.ACTIVITY_CREATED, mock(Listener.class)); diff --git a/navi/src/test/java/com/trello/navi/NaviFragmentTest.java b/navi/src/test/java/com/trello/navi/NaviFragmentTest.java index 81a745b..5a4b162 100644 --- a/navi/src/test/java/com/trello/navi/NaviFragmentTest.java +++ b/navi/src/test/java/com/trello/navi/NaviFragmentTest.java @@ -5,6 +5,8 @@ import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; +import android.view.View; + import com.trello.navi.internal.NaviEmitter; import com.trello.navi.model.ActivityResult; import com.trello.navi.model.RequestPermissionsResult; @@ -79,6 +81,20 @@ public final class NaviFragmentTest { verifyNoMoreInteractions(listener); } + @Test public void onViewCreatedListener() { + Listener listener = mock(Listener.class); + emitter.addListener(Event.VIEW_CREATED, listener); + + Bundle bundle = new Bundle(); + View view = mock(View.class); + emitter.onViewCreated(view, bundle); + verify(listener).call(bundle); + + emitter.removeListener(listener); + emitter.onCreate(bundle); + verifyNoMoreInteractions(listener); + } + @Test public void activityCreatedListener() { Listener listener = mock(Listener.class); emitter.addListener(Event.ACTIVITY_CREATED, listener); @@ -295,9 +311,4 @@ public void restoreInstanceStatePersistableListener() { exception.expect(IllegalArgumentException.class); emitter.addListener(Event.DETACHED_FROM_WINDOW, mock(Listener.class)); } - - @Test public void onViewCreatedListener() { - exception.expect(IllegalArgumentException.class); - emitter.addListener(Event.VIEW_CREATED, mock(Listener.class)); - } } From ec54f443da2348587cf513277187453ef645c7f4 Mon Sep 17 00:00:00 2001 From: gbalabaichkin Date: Wed, 15 Jun 2016 19:09:14 +0300 Subject: [PATCH 3/5] Add new data class --- build.gradle | 2 +- navi/src/main/java/com/trello/navi/Event.java | 3 +- .../com/trello/navi/internal/NaviEmitter.java | 4 +- .../com/trello/navi/model/ViewCreated.java | 39 +++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 navi/src/main/java/com/trello/navi/model/ViewCreated.java diff --git a/build.gradle b/build.gradle index df38058..0dece1f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.5.0' + classpath 'com.android.tools.build:gradle:2.1.2' } } diff --git a/navi/src/main/java/com/trello/navi/Event.java b/navi/src/main/java/com/trello/navi/Event.java index e36b652..6a681c9 100644 --- a/navi/src/main/java/com/trello/navi/Event.java +++ b/navi/src/main/java/com/trello/navi/Event.java @@ -13,6 +13,7 @@ import com.trello.navi.model.ActivityResult; import com.trello.navi.model.BundleBundle; import com.trello.navi.model.RequestPermissionsResult; +import com.trello.navi.model.ViewCreated; /** * Represents an event that can be listened to in an Activity or Fragment. @@ -158,7 +159,7 @@ public final class Event { /** * Emits {@link Fragment#onViewCreated(View, Bundle)} ()}. Emitted before super(). */ - public static final Event VIEW_CREATED = new Event<>(Type.VIEW_CREATED, Bundle.class); + public static final Event VIEW_CREATED = new Event<>(Type.VIEW_CREATED, ViewCreated.class); /** * Emits {@link Fragment#onActivityCreated(Bundle)}. Emitted after super(). diff --git a/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java b/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java index 42ca280..d35b5f2 100644 --- a/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java +++ b/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java @@ -18,6 +18,8 @@ import com.trello.navi.model.ActivityResult; import com.trello.navi.model.BundleBundle; import com.trello.navi.model.RequestPermissionsResult; +import com.trello.navi.model.ViewCreated; + import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -178,7 +180,7 @@ public void onCreateView(Bundle savedInstanceState) { } public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - emitEvent(Event.VIEW_CREATED, savedInstanceState); + emitEvent(Event.VIEW_CREATED, new ViewCreated(view, savedInstanceState)); } public void onDestroy() { diff --git a/navi/src/main/java/com/trello/navi/model/ViewCreated.java b/navi/src/main/java/com/trello/navi/model/ViewCreated.java new file mode 100644 index 0000000..fe981fd --- /dev/null +++ b/navi/src/main/java/com/trello/navi/model/ViewCreated.java @@ -0,0 +1,39 @@ +package com.trello.navi.model; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.View; + +public class ViewCreated { + private final Bundle bundle; + private final View view; + public ViewCreated(View view, @Nullable Bundle bundle) { + this.view = view; + this.bundle = bundle; + } + @Nullable + public Bundle getBundle() { + return bundle; + } + public View getView() { + return view; + } + @Override public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ViewCreated that = (ViewCreated) o; + if (bundle != null ? !bundle.equals(that.bundle) : that.bundle != null) return false; + return view.equals(that.view); + } + @Override public int hashCode() { + int result = bundle != null ? bundle.hashCode() : 0; + result = 31 * result + view.hashCode(); + return result; + } + @Override public String toString() { + return "ViewCreated{" + + "bundle=" + bundle + + ", view=" + view + + '}'; + } +} From b8685612fbff7ddb9abce97a13e8cd84ed806aa0 Mon Sep 17 00:00:00 2001 From: gbalabaichkin Date: Wed, 15 Jun 2016 19:16:35 +0300 Subject: [PATCH 4/5] Fix tests --- .../trello/navi/component/NaviDialogFragment.java | 3 ++- .../com/trello/navi/component/NaviFragment.java | 3 ++- .../support/NaviAppCompatDialogFragment.java | 3 ++- .../trello/navi/component/support/NaviFragment.java | 3 ++- .../java/com/trello/navi/internal/NaviEmitter.java | 4 ++-- .../test/java/com/trello/navi/NaviFragmentTest.java | 13 +++++++------ 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java b/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java index de98093..aa60523 100644 --- a/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java +++ b/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java @@ -16,6 +16,7 @@ import com.trello.navi.Listener; import com.trello.navi.NaviComponent; import com.trello.navi.internal.NaviEmitter; +import com.trello.navi.model.ViewCreated; public class NaviDialogFragment extends DialogFragment implements NaviComponent { @@ -56,7 +57,7 @@ public class NaviDialogFragment extends DialogFragment implements NaviComponent @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - base.onViewCreated(view, savedInstanceState); + base.onViewCreated(new ViewCreated(view, savedInstanceState)); super.onViewCreated(view, savedInstanceState); } diff --git a/navi/src/main/java/com/trello/navi/component/NaviFragment.java b/navi/src/main/java/com/trello/navi/component/NaviFragment.java index 083eda4..1626cc2 100644 --- a/navi/src/main/java/com/trello/navi/component/NaviFragment.java +++ b/navi/src/main/java/com/trello/navi/component/NaviFragment.java @@ -16,6 +16,7 @@ import com.trello.navi.Listener; import com.trello.navi.NaviComponent; import com.trello.navi.internal.NaviEmitter; +import com.trello.navi.model.ViewCreated; public class NaviFragment extends Fragment implements NaviComponent { @@ -56,7 +57,7 @@ public class NaviFragment extends Fragment implements NaviComponent { @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - base.onViewCreated(view, savedInstanceState); + base.onViewCreated(new ViewCreated(view, savedInstanceState)); super.onViewCreated(view, savedInstanceState); } diff --git a/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java b/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java index 434bd92..8cb418d 100644 --- a/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java +++ b/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java @@ -16,6 +16,7 @@ import com.trello.navi.Listener; import com.trello.navi.NaviComponent; import com.trello.navi.internal.NaviEmitter; +import com.trello.navi.model.ViewCreated; public class NaviAppCompatDialogFragment extends DialogFragment implements NaviComponent { @@ -56,7 +57,7 @@ public class NaviAppCompatDialogFragment extends DialogFragment implements NaviC @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - base.onViewCreated(view, savedInstanceState); + base.onViewCreated(new ViewCreated(view, savedInstanceState)); super.onViewCreated(view, savedInstanceState); } diff --git a/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java b/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java index 98e202b..cbc1f4c 100644 --- a/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java +++ b/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java @@ -16,6 +16,7 @@ import com.trello.navi.Listener; import com.trello.navi.NaviComponent; import com.trello.navi.internal.NaviEmitter; +import com.trello.navi.model.ViewCreated; public class NaviFragment extends Fragment implements NaviComponent { @@ -56,7 +57,7 @@ public class NaviFragment extends Fragment implements NaviComponent { @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - base.onViewCreated(view, savedInstanceState); + base.onViewCreated(new ViewCreated(view, savedInstanceState)); super.onViewCreated(view, savedInstanceState); } diff --git a/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java b/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java index d35b5f2..10e4e03 100644 --- a/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java +++ b/navi/src/main/java/com/trello/navi/internal/NaviEmitter.java @@ -179,8 +179,8 @@ public void onCreateView(Bundle savedInstanceState) { emitEvent(Event.CREATE_VIEW, savedInstanceState); } - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - emitEvent(Event.VIEW_CREATED, new ViewCreated(view, savedInstanceState)); + public void onViewCreated(ViewCreated viewCreated) { + emitEvent(Event.VIEW_CREATED, viewCreated); } public void onDestroy() { diff --git a/navi/src/test/java/com/trello/navi/NaviFragmentTest.java b/navi/src/test/java/com/trello/navi/NaviFragmentTest.java index 5a4b162..ff2ba49 100644 --- a/navi/src/test/java/com/trello/navi/NaviFragmentTest.java +++ b/navi/src/test/java/com/trello/navi/NaviFragmentTest.java @@ -10,6 +10,8 @@ import com.trello.navi.internal.NaviEmitter; import com.trello.navi.model.ActivityResult; import com.trello.navi.model.RequestPermissionsResult; +import com.trello.navi.model.ViewCreated; + import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -82,16 +84,15 @@ public final class NaviFragmentTest { } @Test public void onViewCreatedListener() { - Listener listener = mock(Listener.class); + Listener listener = mock(Listener.class); emitter.addListener(Event.VIEW_CREATED, listener); - Bundle bundle = new Bundle(); - View view = mock(View.class); - emitter.onViewCreated(view, bundle); - verify(listener).call(bundle); + ViewCreated result = mock(ViewCreated.class); + emitter.onViewCreated(result); + verify(listener).call(result); emitter.removeListener(listener); - emitter.onCreate(bundle); + emitter.onCreate(new Bundle()); verifyNoMoreInteractions(listener); } From 18078026611bd799dd496f9f09440dee0b5f60f7 Mon Sep 17 00:00:00 2001 From: gbalabaichkin Date: Thu, 16 Jun 2016 10:27:35 +0300 Subject: [PATCH 5/5] Formatting fixes --- .../navi/component/NaviDialogFragment.java | 3 +- .../trello/navi/component/NaviFragment.java | 3 +- .../support/NaviAppCompatDialogFragment.java | 3 +- .../component/support/NaviDialogFragment.java | 6 ++ .../navi/component/support/NaviFragment.java | 3 +- .../com/trello/navi/model/ViewCreated.java | 71 +++++++++++-------- 6 files changed, 50 insertions(+), 39 deletions(-) diff --git a/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java b/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java index aa60523..c41042d 100644 --- a/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java +++ b/navi/src/main/java/com/trello/navi/component/NaviDialogFragment.java @@ -55,8 +55,7 @@ public class NaviDialogFragment extends DialogFragment implements NaviComponent return super.onCreateView(inflater, container, savedInstanceState); } - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { base.onViewCreated(new ViewCreated(view, savedInstanceState)); super.onViewCreated(view, savedInstanceState); } diff --git a/navi/src/main/java/com/trello/navi/component/NaviFragment.java b/navi/src/main/java/com/trello/navi/component/NaviFragment.java index 1626cc2..20a3cf2 100644 --- a/navi/src/main/java/com/trello/navi/component/NaviFragment.java +++ b/navi/src/main/java/com/trello/navi/component/NaviFragment.java @@ -55,8 +55,7 @@ public class NaviFragment extends Fragment implements NaviComponent { return super.onCreateView(inflater, container, savedInstanceState); } - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { base.onViewCreated(new ViewCreated(view, savedInstanceState)); super.onViewCreated(view, savedInstanceState); } diff --git a/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java b/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java index 8cb418d..3c9eb57 100644 --- a/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java +++ b/navi/src/main/java/com/trello/navi/component/support/NaviAppCompatDialogFragment.java @@ -55,8 +55,7 @@ public class NaviAppCompatDialogFragment extends DialogFragment implements NaviC return super.onCreateView(inflater, container, savedInstanceState); } - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { base.onViewCreated(new ViewCreated(view, savedInstanceState)); super.onViewCreated(view, savedInstanceState); } diff --git a/navi/src/main/java/com/trello/navi/component/support/NaviDialogFragment.java b/navi/src/main/java/com/trello/navi/component/support/NaviDialogFragment.java index 7c6b6bc..3cf3245 100644 --- a/navi/src/main/java/com/trello/navi/component/support/NaviDialogFragment.java +++ b/navi/src/main/java/com/trello/navi/component/support/NaviDialogFragment.java @@ -16,6 +16,7 @@ import com.trello.navi.Listener; import com.trello.navi.NaviComponent; import com.trello.navi.internal.NaviEmitter; +import com.trello.navi.model.ViewCreated; public class NaviDialogFragment extends DialogFragment implements NaviComponent { @@ -54,6 +55,11 @@ public class NaviDialogFragment extends DialogFragment implements NaviComponent return super.onCreateView(inflater, container, savedInstanceState); } + @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + base.onViewCreated(new ViewCreated(view, savedInstanceState)); + super.onViewCreated(view, savedInstanceState); + } + @Override @CallSuper public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); base.onActivityCreated(savedInstanceState); diff --git a/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java b/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java index cbc1f4c..458d309 100644 --- a/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java +++ b/navi/src/main/java/com/trello/navi/component/support/NaviFragment.java @@ -55,8 +55,7 @@ public class NaviFragment extends Fragment implements NaviComponent { return super.onCreateView(inflater, container, savedInstanceState); } - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { base.onViewCreated(new ViewCreated(view, savedInstanceState)); super.onViewCreated(view, savedInstanceState); } diff --git a/navi/src/main/java/com/trello/navi/model/ViewCreated.java b/navi/src/main/java/com/trello/navi/model/ViewCreated.java index fe981fd..8f1d472 100644 --- a/navi/src/main/java/com/trello/navi/model/ViewCreated.java +++ b/navi/src/main/java/com/trello/navi/model/ViewCreated.java @@ -5,35 +5,44 @@ import android.view.View; public class ViewCreated { - private final Bundle bundle; - private final View view; - public ViewCreated(View view, @Nullable Bundle bundle) { - this.view = view; - this.bundle = bundle; - } - @Nullable - public Bundle getBundle() { - return bundle; - } - public View getView() { - return view; - } - @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ViewCreated that = (ViewCreated) o; - if (bundle != null ? !bundle.equals(that.bundle) : that.bundle != null) return false; - return view.equals(that.view); - } - @Override public int hashCode() { - int result = bundle != null ? bundle.hashCode() : 0; - result = 31 * result + view.hashCode(); - return result; - } - @Override public String toString() { - return "ViewCreated{" + - "bundle=" + bundle + - ", view=" + view + - '}'; - } + private final Bundle bundle; + private final View view; + + public ViewCreated(View view, @Nullable Bundle bundle) { + this.view = view; + this.bundle = bundle; + } + + public View view() { + return view; + } + + @Nullable + public Bundle bundle() { + return bundle; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ViewCreated that = (ViewCreated) o; + if (bundle != null ? !bundle.equals(that.bundle) : that.bundle != null) return false; + return view.equals(that.view); + } + + @Override + public int hashCode() { + int result = bundle != null ? bundle.hashCode() : 0; + result = 31 * result + view.hashCode(); + return result; + } + + @Override + public String toString() { + return "ViewCreated{" + + "bundle=" + bundle + + ", view=" + view + + '}'; + } }