Search in sources :

Example 56 with Assignment

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

the class MasteryPathOptionsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    mRootView = getLayoutInflater().inflate(R.layout.fragment_mastery_paths_options, container, false);
    mRecyclerAdapter = new MasteryPathOptionsRecyclerAdapter(getContext(), getCanvasContext(), mAssignments, new AdapterToFragmentCallback<Assignment>() {

        @Override
        public void onRowClicked(Assignment assignment, int position, boolean isOpenDetail) {
            Navigation navigation = getNavigation();
            if (navigation != null) {
                Bundle bundle = AssignmentBasicFragment.createBundle(getCanvasContext(), assignment);
                navigation.addFragment(FragUtils.getFrag(AssignmentBasicFragment.class, bundle));
            }
        }

        @Override
        public void onRefreshFinished() {
        }
    });
    configureRecyclerView(mRootView, getContext(), mRecyclerAdapter, R.id.swipeRefreshLayout, R.id.emptyPandaView, R.id.listView);
    // disable the swiperefreshlayout because we don't want to pull to refresh. It doesn't make an API call, so it wouldn't refresh anything
    mRootView.findViewById(R.id.swipeRefreshLayout).setEnabled(false);
    mSelect = (Button) mRootView.findViewById(R.id.select_option);
    mSelect.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ModuleManager.selectMasteryPath(getCanvasContext(), mModuleObjectId, mModuleItemId, mAssignmentSet.getId(), mSelectOptionCallback);
        }
    });
    setupCallbacks();
    return mRootView;
}
Also used : MasteryPathAssignment(com.instructure.canvasapi2.models.MasteryPathAssignment) Assignment(com.instructure.canvasapi2.models.Assignment) Navigation(com.instructure.interactions.Navigation) MasteryPathOptionsRecyclerAdapter(com.instructure.candroid.adapter.MasteryPathOptionsRecyclerAdapter) Bundle(android.os.Bundle) AdapterToFragmentCallback(com.instructure.candroid.interfaces.AdapterToFragmentCallback) View(android.view.View)

Example 57 with Assignment

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

the class ModuleListRecyclerAdapter method getModuleItemsCallback.

private ModuleItemCallback getModuleItemsCallback(final ModuleObject moduleObject, final boolean isNotifyGroupChange) {
    if (mModuleItemCallbacks.containsKey(moduleObject.getId())) {
        return mModuleItemCallbacks.get(moduleObject.getId());
    } else {
        ModuleItemCallback moduleItemCallback = new ModuleItemCallback(moduleObject) {

            private int checkMasteryPaths(int position, ModuleItem item) {
                if (item.getMasteryPaths() != null && item.getMasteryPaths().isLocked()) {
                    // add another module item that says it's locked
                    ModuleItem masteryPathsLocked = new ModuleItem();
                    // set an id so that if there is more than one path we'll display all of them. otherwise addOrUpdateItem will overwrite it
                    masteryPathsLocked.setId(UUID.randomUUID().getLeastSignificantBits());
                    masteryPathsLocked.setTitle(String.format(Locale.getDefault(), getContext().getString(R.string.locked_mastery_paths), item.getTitle()));
                    masteryPathsLocked.setType(ModuleItem.TYPE.Locked.toString());
                    masteryPathsLocked.setCompletionRequirement(null);
                    masteryPathsLocked.setPosition(position++);
                    addOrUpdateItem(this.getModuleObject(), masteryPathsLocked);
                } else if (item.getMasteryPaths() != null && !item.getMasteryPaths().isLocked() && item.getMasteryPaths().getSelectedSetId() == 0) {
                    // add another module item that says select to choose assignment group
                    // We only want to do this when we have a mastery paths object, it's unlocked, and the user hasn't already selected a set
                    ModuleItem masteryPathsSelect = new ModuleItem();
                    // set an id so that if there is more than one path we'll display all of them. otherwise addOrUpdateItem will overwrite it
                    masteryPathsSelect.setId(UUID.randomUUID().getLeastSignificantBits());
                    masteryPathsSelect.setTitle(getContext().getString(R.string.choose_assignment_group));
                    masteryPathsSelect.setType(ModuleItem.TYPE.ChooseAssignmentGroup.toString());
                    masteryPathsSelect.setCompletionRequirement(null);
                    masteryPathsSelect.setPosition(position++);
                    // sort the mastery paths by position
                    ArrayList<AssignmentSet> assignmentSets = new ArrayList<>();
                    assignmentSets.addAll(Arrays.asList(item.getMasteryPaths().getAssignmentSets()));
                    Collections.sort(assignmentSets, new Comparator<AssignmentSet>() {

                        @Override
                        public int compare(AssignmentSet lh, AssignmentSet rh) {
                            if (lh != null && rh != null) {
                                if (lh.getPosition() < rh.getPosition()) {
                                    return -1;
                                } else if (lh.getPosition() > rh.getPosition()) {
                                    return 1;
                                }
                            }
                            return 0;
                        }
                    });
                    AssignmentSet[] set = new AssignmentSet[assignmentSets.size()];
                    assignmentSets.toArray(set);
                    item.getMasteryPaths().setAssignmentSets(set);
                    masteryPathsSelect.setMasteryPathsItemId(item.getId());
                    masteryPathsSelect.setMasteryPaths(item.getMasteryPaths());
                    addOrUpdateItem(this.getModuleObject(), masteryPathsSelect);
                }
                return position;
            }

            @Override
            public void onResponse(@NonNull Response<List<ModuleItem>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                List<ModuleItem> moduleItems = response.body();
                if (type == ApiType.API) {
                    int position = (moduleItems.size() > 0 && moduleItems.get(0) != null) ? moduleItems.get(0).getPosition() - 1 : 0;
                    for (ModuleItem item : moduleItems) {
                        item.setPosition(position++);
                        addOrUpdateItem(this.getModuleObject(), item);
                        position = checkMasteryPaths(position, item);
                    }
                    String nextItemsURL = linkHeaders.nextUrl;
                    if (nextItemsURL != null) {
                        ModuleManager.getNextPageModuleItems(nextItemsURL, this, true);
                    }
                    this.setIsFromNetwork(true);
                    expandGroup(this.getModuleObject(), isNotifyGroupChange);
                } else if (type == ApiType.CACHE) {
                    int position = (moduleItems.size() > 0 && moduleItems.get(0) != null) ? moduleItems.get(0).getPosition() - 1 : 0;
                    for (ModuleItem item : moduleItems) {
                        item.setPosition(position++);
                        addOrUpdateItem(this.getModuleObject(), item);
                    }
                    String nextItemsURL = linkHeaders.nextUrl;
                    if (nextItemsURL != null) {
                        ModuleManager.getNextPageModuleItems(nextItemsURL, this, true);
                    }
                    // Wait for the network to expand when there are no items
                    if (moduleItems.size() > 0) {
                        expandGroup(this.getModuleObject(), isNotifyGroupChange);
                    }
                }
            }

            @Override
            public void onFail(@Nullable Call<List<ModuleItem>> call, @NonNull Throwable error, @Nullable Response response) {
                // Only expand if there was no cache result and no network. No connection empty cell will be displayed
                if (response != null && response.code() == 504 && APIHelper.isCachedResponse(response) && getContext() != null && !Utils.isNetworkAvailable(getContext())) {
                    expandGroup(this.getModuleObject(), isNotifyGroupChange);
                }
            }
        };
        mModuleItemCallbacks.put(moduleObject.getId(), moduleItemCallback);
        return moduleItemCallback;
    }
}
Also used : Call(retrofit2.Call) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) ArrayList(java.util.ArrayList) AssignmentSet(com.instructure.canvasapi2.models.AssignmentSet) Comparator(java.util.Comparator) ModuleItem(com.instructure.canvasapi2.models.ModuleItem) Response(retrofit2.Response) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) Nullable(android.support.annotation.Nullable)

Example 58 with Assignment

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

the class AssignmentBinder method bind.

public static void bind(Context context, final AssignmentViewHolder holder, final Assignment assignment, final int courseColor, final AdapterToFragmentCallback adapterToFragmentCallback) {
    holder.title.setText(assignment.getName());
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            adapterToFragmentCallback.onRowClicked(assignment, holder.getAdapterPosition(), true);
        }
    });
    long courseId = assignment.getCourseId();
    int color = ColorKeeper.getOrGenerateColor(CanvasContext.makeContextId(CanvasContext.Type.COURSE, courseId));
    Submission submission = assignment.getSubmission();
    if (assignment.isMuted()) {
        // mute that score
        holder.points.setVisibility(View.GONE);
    } else {
        holder.points.setVisibility(View.VISIBLE);
        setupGradeText(context, holder.points, assignment, submission, courseColor);
    }
    final int drawable = getAssignmentIcon(assignment);
    holder.icon.setImageDrawable(ColorKeeper.getColoredDrawable(context, drawable, color));
    if (assignment.getDueAt() != null) {
        holder.date.setText(DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, assignment.getDueAt()));
    } else {
        holder.date.setText(context.getResources().getString(R.string.toDoNoDueDate));
    }
    // set description to assignment description or excused
    String description;
    if (submission != null && submission.isExcused()) {
        description = context.getString(R.string.excusedAssignment);
        holder.description.setTypeface(null, Typeface.BOLD);
    } else {
        description = getHtmlAsText(assignment.getDescription());
        holder.description.setTypeface(null, Typeface.NORMAL);
    }
    setCleanText(holder.description, description);
    if (TextUtils.isEmpty(description)) {
        setGone(holder.description);
    } else {
        setVisible(holder.description);
    }
}
Also used : Submission(com.instructure.canvasapi2.models.Submission) View(android.view.View)

Example 59 with Assignment

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

the class ScheduleItemBinder method bind.

public static void bind(final ScheduleItemViewHolder holder, final ScheduleItem item, final Context context, final int courseColor, final String contextName, final AdapterToFragmentCallback<ScheduleItem> adapterToFragmentCallback) {
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            adapterToFragmentCallback.onRowClicked(item, holder.getAdapterPosition(), false);
        }
    });
    switch(item.getItemType()) {
        case TYPE_SYLLABUS:
            {
                holder.title.setText(context.getString(R.string.syllabus));
                Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_syllabus, courseColor);
                holder.icon.setImageDrawable(drawable);
                break;
            }
        case TYPE_CALENDAR:
            {
                Drawable drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_calendar, courseColor);
                holder.icon.setImageDrawable(drawable);
                holder.title.setText(item.getTitle());
                holder.date.setText(item.getStartString(context));
                String description = getHtmlAsText(item.getDescription());
                setupDescription(description, holder.description);
                break;
            }
        case TYPE_ASSIGNMENT:
            holder.title.setText(item.getTitle());
            Drawable drawable;
            Assignment assignment = item.getAssignment();
            if (assignment != null) {
                final int drawableResId = getAssignmentIcon(assignment);
                drawable = ColorKeeper.getColoredDrawable(context, drawableResId, courseColor);
                holder.icon.setImageDrawable(drawable);
                Date dueDate = assignment.getDueAt();
                if (dueDate != null) {
                    String dateString = DateHelper.createPrefixedDateTimeString(context, R.string.toDoDue, dueDate);
                    holder.date.setText(dateString);
                } else {
                    holder.date.setText(context.getResources().getString(R.string.toDoNoDueDate));
                }
                String description = getHtmlAsText(assignment.getDescription());
                setupDescription(description, holder.description);
                // submissions aren't included with the assignments in the api call, so we don't get grades
                // so we'll never see the grade
                setInvisible(holder.points);
            } else {
                drawable = ColorKeeper.getColoredDrawable(context, R.drawable.vd_calendar, courseColor);
                holder.icon.setImageDrawable(drawable);
                holder.date.setText(item.getStartString(context));
                String description = getHtmlAsText(item.getDescription());
                setupDescription(description, holder.description);
            }
            break;
    }
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date)

Example 60 with Assignment

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

the class AssignmentManager method getFirstPageAssignments.

public static void getFirstPageAssignments(CanvasContext canvasContext, final boolean forceNetwork, StatusCallback<List<Assignment>> callback) {
    if (isTesting() || mTesting) {
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        AssignmentAPI.getFirstPageAssignments(canvasContext.getId(), forceNetwork, adapter, callback);
    }
}
Also used : RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Aggregations

Assignment (com.instructure.canvasapi2.models.Assignment)62 Test (org.junit.Test)46 Submission (com.instructure.canvasapi2.models.Submission)25 Date (java.util.Date)18 ArrayList (java.util.ArrayList)15 View (android.view.View)10 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)10 Course (com.instructure.canvasapi2.models.Course)9 RestParams (com.instructure.canvasapi2.builders.RestParams)7 Bundle (android.os.Bundle)6 ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)6 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)6 Navigation (com.instructure.interactions.Navigation)5 DrawableRes (android.support.annotation.DrawableRes)4 AdapterView (android.widget.AdapterView)4 TextView (android.widget.TextView)4 Request (okhttp3.Request)4 Response (okhttp3.Response)4 Paint (android.graphics.Paint)3 Drawable (android.graphics.drawable.Drawable)3