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();
}
}
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();
}
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;
}
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;
}
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());
}
}
Aggregations