Search in sources :

Example 1 with Conversation

use of com.instructure.canvasapi2.models.Conversation 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 Conversation

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

the class AddMessageFragment method onReadySetGo.

@Override
protected void onReadySetGo(AddMessagePresenter presenter) {
    setupToolbar();
    // Set conversation subject
    if (!isNewMessage && !mIsMessageStudentsWho) {
        mSubject.setText(presenter.getConversation().getSubject());
    } else if (mIsMessageStudentsWho) {
        if (mIsPersonalMessage) {
            mSubject.setVisibility(View.GONE);
            mEditSubject.setVisibility(View.VISIBLE);
            mEditSubject.setText(getArguments().getString(MESSAGE_STUDENTS_WHO_SUBJECT));
        } else {
            mSubject.setText(getArguments().getString(MESSAGE_STUDENTS_WHO_SUBJECT));
        }
    }
    // Set up recipients view
    mChipsTextView.setTokenizer(new Rfc822Tokenizer());
    if (mChipsAdapter == null) {
        mChipsAdapter = new RecipientAdapter(getContext());
    }
    if (mChipsTextView.getAdapter() == null) {
        mChipsTextView.setAdapter(mChipsAdapter);
    }
    if (getPresenter().getCourse().getId() != 0) {
        mChipsAdapter.getCanvasRecipientManager().setCanvasContext(getPresenter().getCourse());
    } else if (mSelectedCourse != null) {
        courseWasSelected();
        mChipsAdapter.getCanvasRecipientManager().setCanvasContext(mSelectedCourse);
    }
    ColorUtils.colorIt(ThemePrefs.getButtonColor(), mContactsButton);
    // don't show the contacts button if there is no selected course and there is no context_code from the conversation (shouldn't happen, but it does)
    if (mSelectedCourse == null && getPresenter().getCourse() != null && getPresenter().getCourse().getId() == 0) {
        mContactsButton.setVisibility(View.INVISIBLE);
    }
    mContactsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CanvasContext canvasContext;
            if (getPresenter().getCourse() != null && getPresenter().getCourse().getId() == 0) {
                // presenter doesn't know what the course is, use the mSelectedCourse instead
                canvasContext = mSelectedCourse;
            } else {
                canvasContext = getPresenter().getCourse();
            }
            RouteMatcher.route(getContext(), new Route(ChooseRecipientsFragment.class, canvasContext, ChooseRecipientsFragment.createBundle(canvasContext, getRecipientsFromRecipientEntries())));
        }
    });
    // Ensure attachments are up to date
    refreshAttachments();
    // get courses and groups if this is a new compose message
    if (isNewMessage) {
        getPresenter().getAllCoursesAndGroups(true);
    }
}
Also used : Rfc822Tokenizer(android.text.util.Rfc822Tokenizer) RecipientAdapter(com.instructure.teacher.adapters.RecipientAdapter) CanvasContext(com.instructure.canvasapi2.models.CanvasContext) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) RecipientEditTextView(com.android.ex.chips.RecipientEditTextView) TextView(android.widget.TextView) AddMessageView(com.instructure.teacher.viewinterface.AddMessageView) AttachmentView(com.instructure.pandautils.views.AttachmentView) ScrollView(android.widget.ScrollView) Route(com.instructure.interactions.router.Route)

Example 3 with Conversation

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

the class AddMessageFragment method getPresenterFactory.

@Override
protected PresenterFactory<AddMessagePresenter> getPresenterFactory() {
    Conversation conversation = getArguments().getParcelable(Const.CONVERSATION);
    ArrayList<BasicUser> participants = getArguments().getParcelableArrayList(KEY_PARTICIPANTS);
    ArrayList<Message> messages = getArguments().getParcelableArrayList(Const.MESSAGE);
    boolean isReply = getArguments().getBoolean(KEY_IS_REPLY, false);
    return new AddMessagePresenterFactory(conversation, participants, messages, isReply);
}
Also used : BasicUser(com.instructure.canvasapi2.models.BasicUser) Message(com.instructure.canvasapi2.models.Message) Conversation(com.instructure.canvasapi2.models.Conversation) AddMessagePresenterFactory(com.instructure.teacher.factory.AddMessagePresenterFactory)

Example 4 with Conversation

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

the class ConversationTest method getWorkflowState_read.

@Test
public void getWorkflowState_read() {
    Conversation conversation = new Conversation();
    conversation.setWorkflowState("read");
    assertEquals(Conversation.WorkflowState.READ, conversation.getWorkflowState());
}
Also used : Conversation(com.instructure.canvasapi2.models.Conversation) Test(org.junit.Test)

Example 5 with Conversation

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

the class ConversationTest method hasAttachments.

@Test
public void hasAttachments() {
    Conversation conversation = new Conversation();
    ArrayList<String> properties = new ArrayList<>();
    properties.add("attachments");
    conversation.setProperties(properties);
    assertEquals(true, conversation.hasAttachments());
}
Also used : ArrayList(java.util.ArrayList) Conversation(com.instructure.canvasapi2.models.Conversation) Test(org.junit.Test)

Aggregations

Conversation (com.instructure.canvasapi2.models.Conversation)28 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)20 Test (org.junit.Test)14 RestParams (com.instructure.canvasapi2.builders.RestParams)12 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)9 Response (okhttp3.Response)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)3 List (java.util.List)3 Nullable (android.support.annotation.Nullable)2 Date (java.util.Date)2 Bundle (android.os.Bundle)1 Rfc822Tokenizer (android.text.util.Rfc822Tokenizer)1 Menu (android.view.Menu)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1