Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Add fragment delegate #47

Merged
merged 7 commits into from
Dec 16, 2016
Merged

Add fragment delegate #47

merged 7 commits into from
Dec 16, 2016

Conversation

vRallev
Copy link
Contributor

@vRallev vRallev commented Dec 15, 2016

Add a fragment delegate and remove duplicated code. This allows reusing the fragment code without extending TiFragment or TiDialogFragment.

…ng the fragment code without extending TiFragment or TiDialogFragment
@passsy passsy mentioned this pull request Dec 15, 2016
Pascal Welsch added 3 commits December 15, 2016 18:42
it better belongs to the wiki, the README.md shouldn't be cluttered
It's not possible to pass a single Object into the delegate because in CompositeAndroid the TiViewProvider and the Fragment are different objects. Adding all interfaces one by one helps when testing. There is no god object required which implements all interfaces at once.

Logging tag and toString belong in the Fragments itself rather than the delegate. Before it was using the logging tag "TiFragmentDelegate" instead of "SampleFragment" which doesn't help a lot when debugging

provideView was moved into the Fragments because this works differently between Compositeandroid and the Ti implementations
@passsy passsy requested review from StefMa and a user December 15, 2016 18:38
import android.app.Activity;
import android.support.v4.app.Fragment;

public interface DelegatedTiFragment {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we extend from DelegatedTiActivity? 🤔

Copy link
Contributor Author

@vRallev vRallev Dec 16, 2016

Choose a reason for hiding this comment

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

I'd say no, because of the P getRetainedPresenter(); method.

Copy link

Choose a reason for hiding this comment

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

Sure we could. Or we could rename all activity related callbacks in the DelegatedTiFragment something like: isHostingActivity...

Copy link
Contributor

Choose a reason for hiding this comment

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

some methods overlap, some don't. I don't see a reason for inheritance

Copy link
Contributor

@StefMa StefMa Dec 16, 2016

Choose a reason for hiding this comment

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

some methods overlap

Currently only the P getRetainedPresenter(); don't overlap. The question for me is: Why we haven't it inside the fragment?

I don't see a reason for inheritance

Because a Fragment can only be attached to an Activity. That means a Fragment have always a Activity as "Parent" anywhere...
That's for me a reason enough to use inheritance...

Copy link
Contributor

Choose a reason for hiding this comment

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

Fragment and Activity don't share the same interface although many lifecycle methods are equal. Both work differently. Also methods like isActivityChangingConfigurations() are currently not used by the Fragment but for logging and may be removed soon.

P getRetainedPresenter(); is not required for Fragments because the Fragment Object doesn't die and gets retained together with the delegate automatically.

I'm going with the renaming suggested by @rberghegger

}
}

public void onStop() {
Copy link
Contributor

Choose a reason for hiding this comment

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

In our TiActivityDelegate we have called these method with the suffix _afterSuper.
It would be great if you either

  • Add this prefix here too.
  • Remove the prefix from the TiActivityDelegate
    It is more consistent...

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've added the suffix

@@ -316,6 +316,7 @@ public class HelloWorldActivity extends CompositeActivity implements HelloWorldV
}
```


Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

public void onDestroy() {
//FIXME handle attach/detach state
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix this :)

Copy link
Contributor Author

@vRallev vRallev Dec 16, 2016

Choose a reason for hiding this comment

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

That's an old comment

Copy link
Contributor

Choose a reason for hiding this comment

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

working on that, different PR

super.onStop();
}

@Override
public boolean postToMessageQueue(final Runnable runnable) {
return getActivity().getWindow().getDecorView().post(runnable);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This crashes if no activity isn't attached. Not sure if this can happen, but it's safer to use a Handler.

Copy link
Contributor

Choose a reason for hiding this comment

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

true. It works for us because it's only called in onStart(). But sadly this is public API and should always work. I suggest creating a separate PR for this

@StefMa
Copy link
Contributor

StefMa commented Dec 16, 2016

@vRallev thank you for you contribution!

@StefMa StefMa merged commit a255fc4 into GCX-HCI:master Dec 16, 2016
@vRallev vRallev deleted the feature/add-fragment-delegate branch December 16, 2016 15:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants