Search in sources :

Example 1 with StreamItem

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

the class NotificationListRecyclerAdapter method populateActivityStreamAdapter.

public void populateActivityStreamAdapter() {
    if (mIsNoNetwork) {
        // workaround for the multiple callbacks, which mess up the generic solution
        getAdapterToRecyclerViewCallback().setDisplayNoConnection(true);
        getAdapterToRecyclerViewCallback().setIsEmpty(size() == 0);
    }
    // wait until all calls return;
    if (mCourseMap == null || mGroupMap == null || mStreamItems == null) {
        return;
    }
    for (final StreamItem streamItem : mStreamItems) {
        streamItem.setCanvasContextFromMap(mCourseMap, mGroupMap);
        // load conversations if needed
        if (streamItem.getType() == StreamItem.Type.CONVERSATION && ApiPrefs.getUser() != null) {
            InboxManager.getConversation(streamItem.getConversationId(), false, new StatusCallback<Conversation>() {

                @Override
                public void onResponse(@NonNull Response<Conversation> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    // need to make sure the user isn't null
                    if (ApiPrefs.getUser() != null) {
                        streamItem.setConversation(getContext(), response.body(), ApiPrefs.getUser().getId(), getContext().getString(R.string.monologue));
                        notifyDataSetChanged();
                    }
                }

                @Override
                public void onFail(@Nullable Call<Conversation> call, @NonNull Throwable error, @Nullable Response response) {
                    // Show crouton if it's a network error
                    if (!APIHelper.hasNetworkConnection()) {
                        mAdapterToFragmentCallback.onShowErrorCrouton(R.string.noDataConnection);
                    } else // Otherwise show that it's been deleted if we have a valid user
                    if (ApiPrefs.getUser() != null) {
                        Conversation conversation = new Conversation();
                        conversation.setDeleted(true);
                        conversation.setDeletedString(getContext().getString(R.string.deleted));
                        streamItem.setConversation(getContext(), conversation, ApiPrefs.getUser().getId(), getContext().getString(R.string.monologue));
                        notifyDataSetChanged();
                    }
                }
            });
        }
        // make sure there's something there
        if (streamItem.getUpdatedAtDate() == null) {
            continue;
        }
        addOrUpdateItem(DateHelper.getCleanDate(streamItem.getUpdatedAtDate().getTime()), streamItem);
    }
    mStreamItems = null;
    // update count in dashboard
    if (mOnNotificationCountInvalidated != null) {
        mOnNotificationCountInvalidated.invalidateNotificationsCount();
    }
}
Also used : Response(retrofit2.Response) HiddenStreamItem(com.instructure.canvasapi2.models.HiddenStreamItem) StreamItem(com.instructure.canvasapi2.models.StreamItem) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ApiType(com.instructure.canvasapi2.utils.ApiType) Conversation(com.instructure.canvasapi2.models.Conversation)

Example 2 with StreamItem

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

the class NotificationListRecyclerAdapter method cancelButtonClicked.

public void cancelButtonClicked() {
    for (StreamItem streamItem : mCheckedStreamItems) {
        streamItem.setChecked(false);
    }
    mIsEditMode = false;
    clearMarked();
    notifyDataSetChanged();
}
Also used : HiddenStreamItem(com.instructure.canvasapi2.models.HiddenStreamItem) StreamItem(com.instructure.canvasapi2.models.StreamItem)

Example 3 with StreamItem

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

the class NotificationListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = getLayoutInflater().inflate(R.layout.fragment_list_notification, container, false);
    mToolbar = mRootView.findViewById(R.id.toolbar);
    mAdapterToFragmentCallback = new NotificationAdapterToFragmentCallback<StreamItem>() {

        @Override
        public void onRowClicked(StreamItem streamItem, int position, boolean isOpenDetail) {
            mRecyclerAdapter.setSelectedPosition(position);
            Navigation navigation = getNavigation();
            if (navigation != null) {
                onRowClick(streamItem, isOpenDetail);
            }
        }

        @Override
        public void onRefreshFinished() {
            setRefreshing(false);
            mEditOptions.setVisibility(View.GONE);
        }

        @Override
        public void onShowEditView(boolean isVisible) {
            mEditOptions.setVisibility(isVisible ? View.VISIBLE : View.GONE);
        }

        @Override
        public void onShowErrorCrouton(int message) {
            showToast(message);
        }
    };
    mRecyclerAdapter = new NotificationListRecyclerAdapter(getContext(), getCanvasContext(), onNotificationCountInvalidated, mAdapterToFragmentCallback);
    configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
    PandaRecyclerView pandaRecyclerView = mRootView.findViewById(R.id.listView);
    pandaRecyclerView.setSelectionEnabled(false);
    configureViews(mRootView);
    return mRootView;
}
Also used : Navigation(com.instructure.interactions.Navigation) NotificationListRecyclerAdapter(com.instructure.candroid.adapter.NotificationListRecyclerAdapter) StreamItem(com.instructure.canvasapi2.models.StreamItem) PandaRecyclerView(com.instructure.pandarecycler.PandaRecyclerView)

Example 4 with StreamItem

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

the class NotificationListFragment method addFragmentForStreamItem.

public static DialogFragment addFragmentForStreamItem(StreamItem streamItem, FragmentActivity activity, boolean fromWidget) {
    ParentFragment fragment = null;
    if (streamItem == null || activity == null) {
        return null;
    }
    String unsupportedLabel = null;
    switch(streamItem.getType()) {
        case SUBMISSION:
            if (streamItem.getAssignment() == null && streamItem.getCanvasContext() instanceof Course) {
                fragment = FragUtils.getFrag(AssignmentFragment.class, AssignmentFragment.Companion.createBundle(streamItem.getCanvasContext(), streamItem.getAssignmentId()));
            } else if (streamItem.getAssignment() != null && streamItem.getCanvasContext() instanceof Course) {
                // add an empty submission with the grade to the assignment so that we can see the score.
                Submission emptySubmission = new Submission();
                emptySubmission.setGrade(streamItem.getGrade());
                streamItem.getAssignment().setSubmission(emptySubmission);
                fragment = FragUtils.getFrag(AssignmentFragment.class, AssignmentFragment.Companion.createBundle((Course) streamItem.getCanvasContext(), streamItem.getAssignment()));
            }
            break;
        case ANNOUNCEMENT:
            if (streamItem.getCanvasContext() != null) {
                fragment = FragUtils.getFrag(DiscussionDetailsFragment.class, DiscussionDetailsFragment.makeBundle(streamItem.getCanvasContext(), streamItem.getDiscussionTopicId(), true));
            }
            break;
        case CONVERSATION:
            Conversation conversation = streamItem.getConversation();
            if (conversation != null) {
                // Check to see if the conversation has been deleted.
                if (conversation.isDeleted()) {
                    Toast.makeText(activity, R.string.deleteConversation, Toast.LENGTH_SHORT).show();
                    return null;
                }
                Bundle extras = InboxConversationFragment.createBundle(conversation, 0, null);
                fragment = FragUtils.getFrag(InboxConversationFragment.class, extras);
            }
            break;
        case DISCUSSION_TOPIC:
            if (streamItem.getCanvasContext() != null) {
                fragment = FragUtils.getFrag(DiscussionDetailsFragment.class, DiscussionDetailsFragment.makeBundle(streamItem.getCanvasContext(), streamItem.getDiscussionTopicId(), false));
            }
            break;
        case MESSAGE:
            if (streamItem.getAssignmentId() > 0) {
                if (streamItem.getCanvasContext() != null) {
                    fragment = FragUtils.getFrag(AssignmentFragment.class, AssignmentFragment.Companion.createBundle(activity, streamItem.getCanvasContext(), streamItem.getAssignmentId(), streamItem));
                }
            } else {
                fragment = FragUtils.getFrag(UnknownItemFragment.class, UnknownItemFragment.createBundle(streamItem.getCanvasContext(), streamItem));
            }
            break;
        case COLLABORATION:
            if (streamItem.getCanvasContext() != null) {
                unsupportedLabel = activity.getString(R.string.collaborations);
                fragment = UnSupportedTabFragment.createFragment(UnSupportedTabFragment.class, UnSupportedTabFragment.createBundle(streamItem.getCanvasContext(), Tab.COLLABORATIONS_ID, R.string.collaborations));
            }
            break;
        case CONFERENCE:
            if (streamItem.getCanvasContext() != null) {
                unsupportedLabel = activity.getString(R.string.conferences);
                fragment = UnSupportedTabFragment.createFragment(UnSupportedTabFragment.class, UnSupportedTabFragment.createBundle(streamItem.getCanvasContext(), Tab.CONFERENCES_ID, R.string.conferences));
            }
            break;
        default:
            if (streamItem.getCanvasContext() != null) {
                unsupportedLabel = streamItem.getType().toString();
                fragment = FragUtils.getFrag(UnSupportedFeatureFragment.class, UnSupportedFeatureFragment.createBundle(streamItem.getCanvasContext(), unsupportedLabel, streamItem.getUrl()));
            }
            break;
    }
    if (unsupportedLabel != null) {
        if (activity instanceof Navigation) {
            ((Navigation) activity).addFragment(fragment);
        }
    } else {
        if (activity instanceof Navigation && fragment != null) {
            ((Navigation) activity).addFragment(fragment);
        }
        if (fromWidget) {
            if (streamItem.getUrl() != null) {
                RouterUtils.routeUrl(activity, streamItem.getUrl(), false);
            } else {
                RouterUtils.routeUrl(activity, streamItem.getHtmlUrl(), false);
            }
        }
    }
    return null;
}
Also used : Navigation(com.instructure.interactions.Navigation) Submission(com.instructure.canvasapi2.models.Submission) Bundle(android.os.Bundle) Conversation(com.instructure.canvasapi2.models.Conversation) Course(com.instructure.canvasapi2.models.Course)

Example 5 with StreamItem

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

the class NotificationListFragment method handleIntentExtras.

@Override
public void handleIntentExtras(Bundle extras) {
    super.handleIntentExtras(extras);
    if (extras == null) {
        return;
    }
    if (extras.containsKey(Const.SELECTED_ITEM)) {
        StreamItem streamItem = (StreamItem) extras.getSerializable(Const.SELECTED_ITEM);
        setDefaultSelectedId(streamItem.getId());
    }
}
Also used : StreamItem(com.instructure.canvasapi2.models.StreamItem)

Aggregations

StreamItem (com.instructure.canvasapi2.models.StreamItem)5 HiddenStreamItem (com.instructure.canvasapi2.models.HiddenStreamItem)3 Conversation (com.instructure.canvasapi2.models.Conversation)2 Navigation (com.instructure.interactions.Navigation)2 Bundle (android.os.Bundle)1 NotificationListRecyclerAdapter (com.instructure.candroid.adapter.NotificationListRecyclerAdapter)1 Course (com.instructure.canvasapi2.models.Course)1 Submission (com.instructure.canvasapi2.models.Submission)1 ApiType (com.instructure.canvasapi2.utils.ApiType)1 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)1 PandaRecyclerView (com.instructure.pandarecycler.PandaRecyclerView)1 Response (retrofit2.Response)1