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.

CommandsFragment.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.rthoni.camotion.ui.fragments;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import com.luticate.utils.business.LuPromise;
  5. import com.luticate.utils.dbo.LuMultipleDbo;
  6. import com.rthoni.camotion.business.CommandsBusiness;
  7. import com.rthoni.camotion.dbo.CommandDbo;
  8. import com.rthoni.camotion.ui.views.CommandView;
  9. /**
  10. *
  11. * Created by robin on 11/29/15.
  12. */
  13. public class CommandsFragment extends CamotionFragment<CommandDbo, CommandView> {
  14. public interface OnCommandClickedInterface {
  15. void onCommandClicked(CommandDbo command);
  16. }
  17. private OnCommandClickedInterface onCommandClickedInterface;
  18. @Override
  19. public void onAttach(Context context) {
  20. super.onAttach(context);
  21. if (context instanceof Activity) {
  22. onCommandClickedInterface = (OnCommandClickedInterface) context;
  23. }
  24. }
  25. @Override
  26. public void onDetach() {
  27. super.onDetach();
  28. onCommandClickedInterface = null;
  29. }
  30. @Override
  31. protected LuPromise<LuMultipleDbo<CommandDbo>> getLoadPagePromise(int page, int perPage, String query) {
  32. return CommandsBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), page, perPage)
  33. .map(new LuPromise.LuConverter<CommandDbo.MultipleCommandDbo, LuMultipleDbo<CommandDbo>>() {
  34. @Override
  35. public LuMultipleDbo<CommandDbo> convert(CommandDbo.MultipleCommandDbo data) {
  36. return data;
  37. }
  38. });
  39. }
  40. @Override
  41. protected CommandView getDboView(final CommandDbo command) {
  42. CommandView commandView = new CommandView(getActivity());
  43. commandView.setCamotionDbo(_fullLoginDbo, _currentLocation);
  44. commandView.setCommand(command);
  45. commandView.setOnClickedListener(new LuPromise.LuConsumer<CommandDbo>() {
  46. @Override
  47. public void execute(CommandDbo command) {
  48. onCommandClickedInterface.onCommandClicked(command);
  49. }
  50. });
  51. return commandView;
  52. }
  53. }