You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StopPickerActivity.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package com.rthoni.stssaguenay.ui.activities;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import com.luticate.utils.business.LuPromise;
  7. import com.rthoni.stssaguenay.R;
  8. import com.rthoni.stssaguenay.dbo.FavouriteStopDbo;
  9. import com.rthoni.stssaguenay.dbo.RoutesDbo;
  10. import com.rthoni.stssaguenay.dbo.StopsDbo;
  11. import com.rthoni.stssaguenay.ui.fragments.StopPickerFragment;
  12. import com.rthoni.stssaguenay.ui.fragments.StopRoutesPickerFragment;
  13. import java.util.List;
  14. public class StopPickerActivity extends AppCompatActivity {
  15. public static String STOP_EXTRA_NAME = "STOP_EXTRA";
  16. private StopPickerFragment _stopPickerFragment;
  17. @Override
  18. protected void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.activity_stop_picker);
  21. if (getSupportActionBar() != null) {
  22. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  23. }
  24. goToStops();
  25. }
  26. @Override
  27. public boolean onSupportNavigateUp() {
  28. if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
  29. return super.onSupportNavigateUp();
  30. }
  31. getSupportFragmentManager().popBackStack();
  32. return true;
  33. }
  34. public void goToStops()
  35. {
  36. StopPickerFragment f = new StopPickerFragment();
  37. f.setOnStopSelectedConsumer(new LuPromise.LuConsumer<StopsDbo>() {
  38. @Override
  39. public void execute(StopsDbo data) {
  40. goToRoutes(data);
  41. }
  42. });
  43. getSupportFragmentManager()
  44. .beginTransaction()
  45. .replace(R.id.container, f)
  46. .commit();
  47. }
  48. public void goToRoutes(final StopsDbo stopDbo)
  49. {
  50. StopRoutesPickerFragment f = new StopRoutesPickerFragment();
  51. f.setStopsDbo(stopDbo);
  52. f.setOnRoutesSelected(new LuPromise.LuConsumer<FavouriteStopDbo>() {
  53. @Override
  54. public void execute(FavouriteStopDbo data) {
  55. saveStop(data);
  56. }
  57. });
  58. getSupportFragmentManager()
  59. .beginTransaction()
  60. .replace(R.id.container, f)
  61. .addToBackStack("StopRoutesPickerFragment")
  62. .commit();
  63. }
  64. public void saveStop(FavouriteStopDbo favouriteStopDbo)
  65. {
  66. Intent result = new Intent();
  67. result.putExtra(STOP_EXTRA_NAME, favouriteStopDbo.toString());
  68. setResult(Activity.RESULT_OK, result);
  69. finish();
  70. }
  71. }