/FIntent

Fragment Intent API to do fragment navigation easily

Primary LanguageJava

FIntent API Download Build Status Coverage Status

Join the chat at https://gitter.im/ConsenSys/btcrelay-fetchd

This library helps you to implement fragment navigation easily.

Features

  1. Easy APIs
  2. Clear History
  3. NavigateTo fragment APIs
  4. Reuse fragment instance
  5. Animation support
  6. Start fragment for Result
  7. Auto handling of Fragment commit when the app is not in foreground.

Installation

1. Add repo

repositories {
    maven {
        url  "http://dl.bintray.com/suyambu/android" 
    }
}

2. Dependencies

dependencies {
    compile 'in.ponshere:fintent:1.0'
}

Usage

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();
    }
}
  1. 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"));
    }

}   

Examples

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.

Contributing

Please fork this repository and contribute back using pull requests. Features can be requested using issues. All code, comments, and critiques are greatly appreciated.