This repository has been archived by the owner on May 6, 2024. It is now read-only.
Add certificate in Course Outline tab of Course tabs dashboard. #1046
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,8 +76,8 @@ public interface DownloadListener { | |
private DownloadListener downloadListener; | ||
private boolean isVideoMode; | ||
|
||
public NewCourseOutlineAdapter(Context context, EnrolledCoursesResponse courseData, | ||
IEdxEnvironment environment, NewCourseOutlineAdapter.DownloadListener listener, | ||
public NewCourseOutlineAdapter(final Context context, final EnrolledCoursesResponse courseData, | ||
final IEdxEnvironment environment, NewCourseOutlineAdapter.DownloadListener listener, | ||
boolean isVideoMode, boolean isOnCourseOutline) { | ||
this.context = context; | ||
this.environment = environment; | ||
|
@@ -91,6 +91,16 @@ public NewCourseOutlineAdapter(Context context, EnrolledCoursesResponse courseDa | |
adapterData = new ArrayList(); | ||
if (isOnCourseOutline && !isVideoMode) { | ||
adapterData.add(new SectionRow(SectionRow.COURSE_CARD, null)); | ||
// Add certificate item | ||
if (courseData.isCertificateEarned() && environment.getConfig().areCertificateLinksEnabled()) { | ||
adapterData.add(new SectionRow(SectionRow.COURSE_CERTIFICATE, null, | ||
new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
environment.getRouter().showCertificate(context, courseData); | ||
} | ||
})); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -155,6 +165,11 @@ public final View getView(int position, View convertView, ViewGroup parent) { | |
} | ||
return getCardView(convertView); | ||
} | ||
case SectionRow.COURSE_CERTIFICATE: | ||
if (convertView == null) { | ||
convertView = inflater.inflate(R.layout.row_course_dashboard_cert, parent, false); | ||
} | ||
return getCertificateView(position, convertView); | ||
case SectionRow.LAST_ACCESSED_ITEM: { | ||
if (convertView == null) { | ||
convertView = inflater.inflate(R.layout.row_last_accessed, parent, false); | ||
|
@@ -207,19 +222,23 @@ public void setData(@Nullable CourseComponent component) { | |
* Clear all the course outline rows. | ||
*/ | ||
private void clearCourseOutlineData() { | ||
if (adapterData.isEmpty()) return; | ||
|
||
int startIndex = 0; | ||
// If data for course card is available on the first index, we don't want that cleared | ||
if (adapterData.size() >= 1 && adapterData.get(0).type == SectionRow.COURSE_CARD) { | ||
startIndex++; | ||
if (adapterData.isEmpty()) { | ||
return; | ||
} | ||
// If data for last accessed component is available on the second index, we don't want that cleared | ||
if (adapterData.size() >= 2 && adapterData.get(1).type == SectionRow.LAST_ACCESSED_ITEM) { | ||
startIndex++; | ||
// Get index of first courseware row | ||
int firstCoursewareRowIndex = -1; | ||
int i = 0; | ||
for (SectionRow sectionRow : adapterData) { | ||
if (sectionRow.isCoursewareRow()) { | ||
firstCoursewareRowIndex = i; | ||
break; | ||
} | ||
i++; | ||
} | ||
if (firstCoursewareRowIndex >= 0) { | ||
// Selectively clear adapter's data from a specific index onwards. | ||
adapterData.subList(firstCoursewareRowIndex, adapterData.size()).clear(); | ||
} | ||
// Selectively clear adapter's data from a specific index onwards. | ||
adapterData.subList(startIndex, adapterData.size()).clear(); | ||
} | ||
|
||
/** | ||
|
@@ -228,19 +247,15 @@ private void clearCourseOutlineData() { | |
* @return <code>true</code> if there are course items, <code>false</code> otherwise. | ||
*/ | ||
public boolean hasCourseData() { | ||
if (adapterData.isEmpty()) return false; | ||
|
||
int rowsToIgnore = 0; | ||
// If data for course card is available on the first index, we need to skip it | ||
if (adapterData.size() >= 1 && adapterData.get(0).type == SectionRow.COURSE_CARD) { | ||
rowsToIgnore++; | ||
if (adapterData.isEmpty()) { | ||
return false; | ||
} | ||
// If data for last accessed component is available on the second index, we need to skip it | ||
if (adapterData.size() >= 2 && adapterData.get(1).type == SectionRow.LAST_ACCESSED_ITEM) { | ||
rowsToIgnore++; | ||
for (SectionRow sectionRow : adapterData) { | ||
if (sectionRow.isCoursewareRow()) { | ||
return true; | ||
} | ||
} | ||
// Means we have atleast 1 courseware item other than the course card and last accessed item | ||
return adapterData.size() > rowsToIgnore; | ||
return false; | ||
} | ||
|
||
public void reloadData() { | ||
|
@@ -571,6 +586,12 @@ public View getCardView(View view) { | |
return view; | ||
} | ||
|
||
private View getCertificateView(int position, View convertView) { | ||
final SectionRow sectionRow = getItem(position); | ||
convertView.setOnClickListener(sectionRow.clickListener); | ||
return convertView; | ||
} | ||
|
||
private View getLastAccessedView(int position, View convertView) { | ||
final SectionRow sectionRow = getItem(position); | ||
final TextView lastAccessTextView = (TextView) convertView.findViewById(R.id.last_accessed_text); | ||
|
@@ -587,16 +608,62 @@ private View getLastAccessedView(int position, View convertView) { | |
* @param onClickListener The listener to invoke when the `view` button is pressed. | ||
*/ | ||
public void addLastAccessedView(CourseComponent lastAccessedComponent, View.OnClickListener onClickListener) { | ||
final int lastAccessedItemPlace = getNonCourseWareItemPlace(SectionRow.LAST_ACCESSED_ITEM); | ||
// Update the last accessed item, if its already there in the list | ||
if (adapterData.size() >= 2 && adapterData.get(1).type == SectionRow.LAST_ACCESSED_ITEM) { | ||
adapterData.set(1, new SectionRow(SectionRow.LAST_ACCESSED_ITEM, lastAccessedComponent, onClickListener)); | ||
if (lastAccessedItemPlace >= 0) { | ||
adapterData.set(lastAccessedItemPlace, new SectionRow(SectionRow.LAST_ACCESSED_ITEM, lastAccessedComponent, onClickListener)); | ||
} else { | ||
// Add it otherwise | ||
adapterData.add(1, new SectionRow(SectionRow.LAST_ACCESSED_ITEM, lastAccessedComponent, onClickListener)); | ||
adapterData.add(getLastAccessedItemPlace(), new SectionRow(SectionRow.LAST_ACCESSED_ITEM, lastAccessedComponent, onClickListener)); | ||
} | ||
notifyDataSetChanged(); | ||
} | ||
|
||
/** | ||
* Tells the appropriate place for a {@link SectionRow#LAST_ACCESSED_ITEM} to put in the adapters list. | ||
* | ||
* @return list index (non-negative number) for a {@link SectionRow#LAST_ACCESSED_ITEM}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. List index |
||
*/ | ||
public int getLastAccessedItemPlace() { | ||
return isNonCourseWareItemExist(SectionRow.COURSE_CERTIFICATE) ? 2 : 1; | ||
} | ||
|
||
/** | ||
* Tells if specified non-courseware item exist in adapter list or not. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exists in the adapter's list or not. |
||
* | ||
* @param sectionType A non-courseware section type whose existence needs to be checked. | ||
* @return <code>true</code> if specified non-courseware item exist in adapter list, | ||
* <code>false</code> otherwise. | ||
*/ | ||
public boolean isNonCourseWareItemExist(int sectionType) { | ||
return getNonCourseWareItemPlace(sectionType) >= 0; | ||
} | ||
|
||
/** | ||
* Tells the place of a non-courseware item exist in adapter list. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tells the place of a non-courseware item's existence in the adapter's list. |
||
* | ||
* @param sectionType A non-courseware section type whose place needs to be identified. | ||
* @return list index (non-negative number) of a specified non-courseware item, -1 in case item | ||
* doesn't exist. | ||
*/ | ||
public int getNonCourseWareItemPlace(int sectionType) { | ||
if (adapterData.isEmpty()) { | ||
return -1; | ||
} | ||
SectionRow sectionRow; | ||
for (int i = 0; i < adapterData.size(); i++) { | ||
sectionRow = adapterData.get(i); | ||
// return on finding first courseware item | ||
if (sectionRow.isCoursewareRow()) { | ||
break; | ||
} | ||
if (sectionRow.type == sectionType) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
public ViewHolder getTag(View convertView) { | ||
ViewHolder holder = new ViewHolder(); | ||
holder.rowType = (IconImageView) convertView | ||
|
@@ -642,12 +709,14 @@ public static class ViewHolder { | |
} | ||
|
||
public static class SectionRow { | ||
public static final int ITEM = 0; | ||
public static final int SECTION = 1; | ||
public static final int COURSE_CARD = 2; | ||
public static final int LAST_ACCESSED_ITEM = 3; | ||
public static final int COURSE_CARD = 0; | ||
public static final int COURSE_CERTIFICATE = 1; | ||
public static final int LAST_ACCESSED_ITEM = 2; | ||
public static final int SECTION = 3; | ||
public static final int ITEM = 4; | ||
|
||
// Update this count according to the section types mentioned above | ||
public static final int NUM_OF_SECTION_ROWS = 4; | ||
public static final int NUM_OF_SECTION_ROWS = 5; | ||
|
||
public final int type; | ||
public final boolean topComponent; | ||
|
@@ -672,6 +741,11 @@ public SectionRow(int type, boolean topComponent, CourseComponent component, Vie | |
this.component = component; | ||
this.clickListener = listener; | ||
} | ||
|
||
public boolean isCoursewareRow() { | ||
return this.type == ITEM || | ||
this.type == SECTION; | ||
} | ||
} | ||
|
||
public int getPositionByItemId(String itemId) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adapter's list.