Search in sources :

Example 11 with Conversation

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

the class InboxManager method getConversation.

public static void getConversation(long conversationId, boolean forceNetwork, StatusCallback<Conversation> callback) {
    if (isTesting() || mTesting) {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withPerPageQueryParam(false).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        InboxManager_Test.getConversation(adapter, callback, params, conversationId);
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withPerPageQueryParam(false).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        InboxApi.getConversation(adapter, callback, params, conversationId);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 12 with Conversation

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

the class InboxManager method addMessage.

public static void addMessage(long conversationId, String message, List<String> recipientIds, long[] includedMessageIds, long[] attachmentIds, StatusCallback<Conversation> callback) {
    if (isTesting() || mTesting) {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withShouldIgnoreToken(false).withPerPageQueryParam(false).build();
        InboxManager_Test.addMessage(adapter, callback, params, conversationId, recipientIds, message, includedMessageIds, attachmentIds);
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withShouldIgnoreToken(false).withPerPageQueryParam(false).build();
        InboxApi.addMessage(adapter, callback, params, conversationId, recipientIds, message, includedMessageIds, attachmentIds);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 13 with Conversation

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

the class InboxManager method deleteMessages.

public static void deleteMessages(long conversationId, List<Long> messageIds, StatusCallback<Conversation> callback) {
    if (isTesting() || mTesting) {
        InboxManager_Test.deleteMessages(conversationId, messageIds, callback);
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withShouldIgnoreToken(false).withPerPageQueryParam(false).build();
        InboxApi.deleteMessages(adapter, callback, params, conversationId, messageIds);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 14 with Conversation

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

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

the class InboxManager_Test method getConversations.

public static void getConversations(@NonNull InboxApi.Scope scope, @NonNull RestBuilder adapter, @NonNull StatusCallback<List<Conversation>> callback, @NonNull RestParams params) {
    // TODO:
    Response response = new Response.Builder().code(200).message("todo").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "todo".getBytes())).addHeader("content-type", "application/json").build();
    List<Conversation> conversations = new ArrayList<>();
    retrofit2.Response<List<Conversation>> response1 = retrofit2.Response.success(conversations, response);
    callback.onResponse(response1, new LinkHeaders(), ApiType.CACHE);
}
Also used : Response(okhttp3.Response) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) Conversation(com.instructure.canvasapi2.models.Conversation) ArrayList(java.util.ArrayList) List(java.util.List)

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