Search in sources :

Example 11 with Poll

use of com.instructure.canvasapi2.models.Poll in project instructure-android by instructure.

the class PollSessionListFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setHasOptionsMenu(true);
    touchListener = new SwipeDismissListViewTouchListener(getListView(), new SwipeDismissListViewTouchListener.DismissCallbacks() {

        @Override
        public boolean canDismiss(int position) {
            return true;
        }

        @Override
        public void onDismiss(ListView listView, int[] reverseSortedPositions) {
            for (int position : reverseSortedPositions) {
                // set the poll that we want to remove after the api call returns successfully
                PollSession pollSession = getItem(position);
                // remove the item from the list
                removeItem(pollSession);
                // delete the poll from canvas
                PollsManager.deletePollSession(poll.getId(), pollSession.getId(), responseCanvasCallback, true);
            }
        }
    });
    getListView().setOnTouchListener(touchListener);
    getListView().setOnScrollListener(touchListener.makeScrollListener());
    // set an animation for adding list items
    LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(getActivity(), R.anim.list_layout_controller);
    getListView().setLayoutAnimation(controller);
}
Also used : SwipeDismissListViewTouchListener(com.instructure.androidpolling.app.util.SwipeDismissListViewTouchListener) PollSession(com.instructure.canvasapi2.models.PollSession) ListView(android.widget.ListView) LayoutAnimationController(android.view.animation.LayoutAnimationController)

Example 12 with Poll

use of com.instructure.canvasapi2.models.Poll in project instructure-android by instructure.

the class PollSessionListFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Constants.PUBLISH_POLL_SUCCESS || resultCode == Constants.PUBLISH_POLL_SUCCESS_MULTIPLE) {
        if (data != null) {
            PollSession session = data.getExtras().getParcelable(Constants.POLL_SESSION);
            PollResultsFragment pollResultsFragment = new PollResultsFragment();
            Bundle bundle = new Bundle();
            bundle.putParcelable(Constants.POLL_DATA, poll);
            bundle.putParcelable(Constants.POLL_SESSION, session);
            pollResultsFragment.setArguments(bundle);
            ((FragmentManagerActivity) getActivity()).removeFragment(this);
            ((FragmentManagerActivity) getActivity()).swapFragments(pollResultsFragment, PollResultsFragment.class.getSimpleName());
            return;
        }
        reloadData();
    }
}
Also used : PollSession(com.instructure.canvasapi2.models.PollSession) Bundle(android.os.Bundle) FragmentManagerActivity(com.instructure.androidpolling.app.activities.FragmentManagerActivity)

Aggregations

PollSession (com.instructure.canvasapi2.models.PollSession)7 Bundle (android.os.Bundle)4 Poll (com.instructure.canvasapi2.models.Poll)3 PollChoice (com.instructure.canvasapi2.models.PollChoice)3 PollSessionResponse (com.instructure.canvasapi2.models.PollSessionResponse)3 ApiType (com.instructure.canvasapi2.utils.ApiType)3 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)3 Response (retrofit2.Response)3 ListView (android.widget.ListView)2 FragmentManagerActivity (com.instructure.androidpolling.app.activities.FragmentManagerActivity)2 PollChoiceResponse (com.instructure.canvasapi2.models.PollChoiceResponse)2 Section (com.instructure.canvasapi2.models.Section)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ResponseBody (okhttp3.ResponseBody)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 Time (android.text.format.Time)1 View (android.view.View)1 LayoutAnimationController (android.view.animation.LayoutAnimationController)1