Search in sources :

Example 1 with BotCommand

use of im.actor.core.entity.BotCommand in project actor-platform by actorapp.

the class AutocompleteFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    autocompleteList = new BottomSheetListView(getContext());
    autocompleteList.setVisibility(View.INVISIBLE);
    autocompleteList.setUnderlyingView(underlyingView);
    autocompleteList.setDivider(null);
    autocompleteList.setDividerHeight(0);
    autocompleteList.setBackgroundColor(Color.TRANSPARENT);
    if (autocompleteAdapter != null) {
        autocompleteList.setAdapter(autocompleteAdapter);
    }
    autocompleteList.setOnItemClickListener((adapterView, view, i, l) -> {
        Object item = autocompleteAdapter.getItem(i);
        if (item instanceof MentionFilterResult) {
            String mention = ((MentionFilterResult) item).getMentionString();
            Fragment parent = getParentFragment();
            if (parent instanceof AutocompleteCallback) {
                ((AutocompleteCallback) parent).onMentionPicked(mention);
            }
        } else if (item instanceof BotCommand) {
            String command = ((BotCommand) item).getSlashCommand();
            Fragment parent = getParentFragment();
            if (parent instanceof AutocompleteCallback) {
                ((AutocompleteCallback) parent).onCommandPicked(command);
            }
        }
    });
    // Initial zero height
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.BOTTOM;
    autocompleteList.setLayoutParams(params);
    return autocompleteList;
}
Also used : BotCommand(im.actor.core.entity.BotCommand) FrameLayout(android.widget.FrameLayout) MentionFilterResult(im.actor.core.entity.MentionFilterResult) BottomSheetListView(im.actor.sdk.view.adapters.BottomSheetListView) BaseFragment(im.actor.sdk.controllers.BaseFragment) Fragment(android.support.v4.app.Fragment) Nullable(android.support.annotation.Nullable)

Example 2 with BotCommand

use of im.actor.core.entity.BotCommand in project actor-platform by actorapp.

the class CommandsAdapter method setQuery.

public void setQuery(String q) {
    if (q == null || q.equals(query)) {
        return;
    }
    query = q;
    ArrayList<BotCommand> filterd = new ArrayList<BotCommand>();
    for (BotCommand command : commands) {
        if (command.getSlashCommand().toLowerCase().startsWith(q)) {
            filterd.add(command);
        }
    }
    commandsToShow.clear();
    commandsToShow.addAll(filterd);
    notifyDataSetChanged();
}
Also used : BotCommand(im.actor.core.entity.BotCommand) ArrayList(java.util.ArrayList)

Aggregations

BotCommand (im.actor.core.entity.BotCommand)2 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 FrameLayout (android.widget.FrameLayout)1 MentionFilterResult (im.actor.core.entity.MentionFilterResult)1 BaseFragment (im.actor.sdk.controllers.BaseFragment)1 BottomSheetListView (im.actor.sdk.view.adapters.BottomSheetListView)1 ArrayList (java.util.ArrayList)1