Skip to content

Tired of rewriting the same code just to handle fragments? Forgetting the awesome transitions that you can do? Want to make sure the backstack is being handled? Then EasyFragments is probably for you. This library takes all the code used for fragments and simplifies it so you do have to keep rewriting it.

License

Notifications You must be signed in to change notification settings

jmiecz/EasyFragments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

EasyFragments

Tired of rewriting the same code just to handle fragments? Forgetting the awesome transitions that you can do? Want to make sure the backstack is being handled? Then EasyFragments is probably for you. This library takes all the code used for fragments and simplifies it so you do have to keep rewriting it.

How to add a fragment

Adding a fragment will cause it to layer. For example, if you have FragmentA and you add FragmentB. FragmentA will still exist and be drawn but will be under FragmentB.

//Recommend making this a global for your activity and initialize this in onCreate()
FragmentHandler fragmentHandler = new FragmentHandler(activity);
fragmentHandler.add(new FragmentSettings("MY_BACKSTACK_TAG"),
		new FragmentContainer(new Fragment(), R.id.placeholder, "FRAGMENT_TAG"));

For supportedFragments

//Recommend making this a global for your activity and initialize this in onCreate()
SupportedFragmentHandler fragmentHandler = new SupportedFragmentHandler(fragmentActivity);
fragmentHandler.add(new FragmentSettings("MY_BACKSTACK_TAG"),
		new SupportedFragmentContainer(new Fragment(), R.id.placeholder, "FRAGMENT_TAG"));

How to replace a fragment

Replacing a fragment will replace whatever fragment is currently at the place holder. This will call onResume for the new fragment and onPause for the old fragment. If you press the back button and have a backStackTag, the old fragment will have onResume called. This does not happen for add.

//Recommend making this a global for your activity and initialize this in onCreate()
FragmentHandler fragmentHandler = new FragmentHandler(activity);
fragmentHandler.add(new FragmentSettings("MY_BACKSTACK_TAG"),
		new FragmentContainer(new Fragment(), R.id.placeholder, "FRAGMENT_TAG"));

For supportedFragments

//Recommend making this a global for your activity and initialize this in onCreate()
SupportedFragmentHandler fragmentHandler = new SupportedFragmentHandler(fragmentActivity);
fragmentHandler.add(new FragmentSettings("MY_BACKSTACK_TAG"),
		new SupportedFragmentContainer(new Fragment(), R.id.placeholder, "FRAGMENT_TAG"));

How to remove a fragment

This will remove the fragment as well as remove it from the backStack if it was added to it

//Recommend making this a global for your activity and initialize this in onCreate()
FragmentHandler fragmentHandler = new FragmentHandler(activity);
fragmentHandler.remove(new FragmentSettings(),
                "FRAGMENT_TAG");

For supportedFragments

//Recommend making this a global for your activity and initialize this in onCreate()
SupportedFragmentHandler fragmentHandler = new SupportedFragmentHandler(fragmentActivity);
fragmentHandler.remove(new FragmentSettings(),
                "FRAGMENT_TAG");

How to show DialogFragments

//Recommend making this a global for your activity and initialize this in onCreate()
FragmentHandler fragmentHandler = new FragmentHandler(activity);
fragmentHandler.show(new FragmentSettings("MY_BACKSTACK_TAG"),
		new FragmentContainer(new DialogFragment(), "FRAGMENT_TAG"));

For supportedFragments

//Recommend making this a global for your activity and initialize this in onCreate()
SupportedFragmentHandler fragmentHandler = new SupportedFragmentHandler(fragmentActivity);
fragmentHandler.show(new FragmentSettings("MY_BACKSTACK_TAG"),
		new SupportedFragmentContainer(new DialogFragment(), "FRAGMENT_TAG"));

#Notes You can pass it x number of FragmentContainers or tags as you like.

Please make sure to use an unique tag for the backStack and your fragments. For fragments, I recommend using the YourCustomFragment.class.getName().

About

Tired of rewriting the same code just to handle fragments? Forgetting the awesome transitions that you can do? Want to make sure the backstack is being handled? Then EasyFragments is probably for you. This library takes all the code used for fragments and simplifies it so you do have to keep rewriting it.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages