This library helps you to implement fragment navigation easily.
- Easy APIs
- Clear History
- NavigateTo fragment APIs
- Reuse fragment instance
- Animation support
- Start fragment for Result
- Auto handling of Fragment commit when the app is not in foreground.
1. Add repo
repositories {
maven {
url "http://dl.bintray.com/suyambu/android"
}
}
2. Dependencies
dependencies {
compile 'in.ponshere:fintent:1.0'
}
1. Setup FIntentController
public class MainActivity extends AppCompatActivity implements IFIntentActivity {
FIntentController controller;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
controller = FIntentFactory.getInstance().createFIntentController(this,R.id.rlContainer);
controller.startFragment(new FIntent(US1FragmentB.class,"top_fragment"));
}
@Override
public void onBackPressed() {
controller.onBackPressed();
}
@Override
public void callSuperBackPressed() {
super.onBackPressed();
}
}
- Extend FIntentFragment class and directly start using its APIs
public class US1FragmentA extends FIntentFragment<BindingUS1FragmentA> implements View.OnClickListener{
@Override
protected void onViewCreated(@Nullable Bundle savedInstanceState) {
super.onViewCreated(savedInstanceState);
binding.btnNext.setOnClickListener(this);
}
@Override
public int getLayoutResourceId() {
return R.layout.us1_fragment_a;
}
@Override
public void onClick(View view) {
startFragment(new FIntent(US1FragmentB.class,"AtoB"));
}
}
1. Starting next fragment
startFragment(new FIntent(US1FragmentB.class,"FragA"));
2. Exit the current fragment
finish()
3. Clear History
startFragment(new FIntent(US2FragmentD.class,"FragC").addFlag(FIntent.FLAGS.CLEAR_HISTORY));
4. Transition Animation
startFragment(new FIntent(US1FragmentB.class,"FragA").setAnimationType(FIntent.AnimationType.SLIDE_UP_DOWN));
5. Start fragment for result
static final int REQUEST_CODE = 1000;
public void onClick(View view) {
startFragmentForResult(new FIntent(US6FragmentB.class,US6FragmentA),REQUEST_CODE);
}
@Override
public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
super.onFragmentResult(requestCode, resultCode, data);
if(requestCode == REQUEST_CODE){
if(resultCode == OK){
}else if(resultCode == CANCELLED){
}
}
}
Please refer the sample app for complete samples.
Please fork this repository and contribute back using pull requests. Features can be requested using issues. All code, comments, and critiques are greatly appreciated.