package com.rthoni.stssaguenay.ui.activities; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import com.luticate.utils.business.LuPromise; import com.rthoni.stssaguenay.R; import com.rthoni.stssaguenay.dbo.StopsDbo; import com.rthoni.stssaguenay.ui.fragments.StopPickerFragment; import com.rthoni.stssaguenay.ui.fragments.StopRoutesPickerFragment; public class StopPickerActivity extends AppCompatActivity { private StopPickerFragment _stopPickerFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stop_picker); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } goToStops(); } @Override public boolean onSupportNavigateUp() { if (getSupportFragmentManager().getBackStackEntryCount() == 0) { return super.onSupportNavigateUp(); } getSupportFragmentManager().popBackStack(); return true; } public void goToStops() { StopPickerFragment f = new StopPickerFragment(); f.setOnStopSelectedConsumer(new LuPromise.LuConsumer() { @Override public void execute(StopsDbo data) { goToRoutes(data); } }); getSupportFragmentManager() .beginTransaction() .replace(R.id.container, f) .commit(); } public void goToRoutes(StopsDbo stopDbo) { StopRoutesPickerFragment f = new StopRoutesPickerFragment(); f.setStopsDbo(stopDbo); getSupportFragmentManager() .beginTransaction() .replace(R.id.container, f) .addToBackStack("StopRoutesPickerFragment") .commit(); } }