123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package com.rthoni.camotion.ui.fragments;
-
- import android.app.Activity;
- import android.content.Context;
-
- import com.luticate.utils.business.LuPromise;
- import com.luticate.utils.dbo.LuMultipleDbo;
- import com.rthoni.camotion.business.CommandsBusiness;
- import com.rthoni.camotion.dbo.CommandDbo;
- import com.rthoni.camotion.ui.views.CommandView;
-
- /**
- *
- * Created by robin on 11/29/15.
- */
- public class CommandsFragment extends CamotionFragment<CommandDbo, CommandView> {
-
- public interface OnCommandClickedInterface {
- void onCommandClicked(CommandDbo command);
- }
-
- private OnCommandClickedInterface onCommandClickedInterface;
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
-
- if (context instanceof Activity) {
- onCommandClickedInterface = (OnCommandClickedInterface) context;
- }
- }
-
- @Override
- public void onDetach() {
- super.onDetach();
- onCommandClickedInterface = null;
- }
-
- @Override
- protected LuPromise<LuMultipleDbo<CommandDbo>> getLoadPagePromise(int page, int perPage, String query) {
- return CommandsBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), page, perPage)
- .map(new LuPromise.LuConverter<CommandDbo.MultipleCommandDbo, LuMultipleDbo<CommandDbo>>() {
- @Override
- public LuMultipleDbo<CommandDbo> convert(CommandDbo.MultipleCommandDbo data) {
- return data;
- }
- });
- }
-
- @Override
- protected CommandView getDboView(final CommandDbo command) {
- CommandView commandView = new CommandView(getActivity());
- commandView.setCamotionDbo(_fullLoginDbo, _currentLocation);
- commandView.setCommand(command);
- commandView.setOnClickedListener(new LuPromise.LuConsumer<CommandDbo>() {
- @Override
- public void execute(CommandDbo command) {
- onCommandClickedInterface.onCommandClicked(command);
- }
- });
- return commandView;
- }
- }
|