Skip to content

Commit

Permalink
[Student][Teacher] Add comment indicators to annotations (#1067)
Browse files Browse the repository at this point in the history
* [Student][Teacher] Add comment indicators to annotations

* fix for student styling

* cleaned up the student pdf styles

* get things up to date with master

* bug fix for icon indicator, so it doesnt interfere with the comment fab

* new fixes
  • Loading branch information
TrevorNeedham authored Oct 20, 2020
1 parent 70917b7 commit 5cd48cb
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class PdfStudentSubmissionView(
if (event.isHeadAnnotation) {
//we need to delete the entire list of comments from the hashmap
commentRepliesHashMap.remove(event.annotation.inReplyTo)
pdfFragment?.selectedAnnotations?.get(0)?.contents = ""
noteHinter?.notifyDrawablesChanged()
} else {
//otherwise just remove the comment
commentRepliesHashMap[event.annotation.inReplyTo]?.remove(event.annotation)
Expand Down
18 changes: 7 additions & 11 deletions apps/student/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<item name="android:windowAnimationStyle">@null</item>
</style>

<!-- Used for stand alone PSPDFKit activity, pdf fragment uses values in CanvasMaterialTheme_Default-->
<style name="PSPDFKitTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/annotationToolbarBackground</item>
<item name="colorAccent">@color/annotationToolbarBackground</item>
Expand All @@ -47,17 +48,6 @@
<item name="pspdf__annotationCreationToolbarIconsStyle">@style/PSPDFAnnotationCreationToolbarIconsStyle</item>
</style>

<style name="SubmissionPSPDFKitTheme" parent="CanvasMaterialTheme_Default">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="pspdf__contextualToolbarStyle">@style/ContextualToolbarStyle</item>
<item name="pspdf__annotationCreationToolbarIconsStyle">@style/AnnotationCreationToolbarIconsStyle</item>
<item name="pspdf__annotationEditingToolbarIconsStyle">@style/AnnotationEditingToolbarIconsStyle</item>
<item name="pspdf__stampPickerStyle">@style/StampPickerStyle</item>
<item name="pspdf__modalDialogStyle">@style/ModalDialogStyle</item>
</style>

<style name="ContextualToolbarStyle">
<item name="pspdf__backgroundColor">@color/annotationToolbarBackground</item>
<item name="pspdf__submenuBackgroundColor">@color/submenuAnnotationToolbarBackground</item>
Expand All @@ -79,6 +69,12 @@
<item name="pspdf__editIcon">@drawable/ic_edit</item>
</style>

<style name="AnnotationNoteHinter">
<item name="pspdf__noteHinterColor">@color/blueAnnotation</item>
<item name="pspdf__noteHinterAlpha">255</item>
<item name="pspdf__noteHinterIcon">@drawable/ic_annotation_comment_indicator</item>
</style>

<style name="StampPickerStyle">
<item name="pspdf__titleBackground">@color/annotationToolbarBackground</item>
<item name="pspdf__maxHeight">320dp</item>
Expand Down
6 changes: 6 additions & 0 deletions apps/student/src/main/res/values/themes_canvastheme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<item name="windowActionModeOverlay">true</item>
<item name="android:alertDialogTheme">@style/CanvasDialogTheme_Default</item>
<item name="alertDialogTheme">@style/CanvasDialogTheme_Default</item>
<item name="pspdf__contextualToolbarStyle">@style/ContextualToolbarStyle</item>
<item name="pspdf__annotationCreationToolbarIconsStyle">@style/AnnotationCreationToolbarIconsStyle</item>
<item name="pspdf__annotationEditingToolbarIconsStyle">@style/AnnotationEditingToolbarIconsStyle</item>
<item name="pspdf__stampPickerStyle">@style/StampPickerStyle</item>
<item name="pspdf__modalDialogStyle">@style/ModalDialogStyle</item>
<item name="pspdf__annotationNoteHinterStyle">@style/AnnotationNoteHinter</item>
</style>

<style name="CanvasMaterialTheme_Default.Translucent">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ class SubmissionContentView(
if (event.isHeadAnnotation) {
//we need to delete the entire list of comments from the hashmap
commentRepliesHashMap.remove(event.annotation.inReplyTo)
pdfFragment?.selectedAnnotations?.get(0)?.contents = ""
noteHinter?.notifyDrawablesChanged()
} else {
//otherwise just remove the comment
commentRepliesHashMap[event.annotation.inReplyTo]?.remove(event.annotation)
Expand Down
7 changes: 7 additions & 0 deletions apps/teacher/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<item name="pspdf__annotationCreationToolbarIconsStyle">@style/AnnotationCreationToolbarIconsStyle</item>
<item name="pspdf__annotationEditingToolbarIconsStyle">@style/AnnotationEditingToolbarIconsStyle</item>
<item name="pspdf__stampPickerStyle">@style/StampPickerStyle</item>
<item name="pspdf__annotationNoteHinterStyle">@style/AnnotationNoteHinter</item>
</style>

<style name="ContextualToolbarStyle">
Expand All @@ -56,6 +57,12 @@
<item name="pspdf__editIcon">@drawable/ic_edit</item>
</style>

<style name="AnnotationNoteHinter">
<item name="pspdf__noteHinterColor">@color/blueAnnotation</item>
<item name="pspdf__noteHinterAlpha">255</item>
<item name="pspdf__noteHinterIcon">@drawable/ic_annotation_comment_indicator</item>
</style>

<style name="StampPickerStyle">
<item name="pspdf__maxHeight">320dp</item>
<item name="pspdf__maxWidth">100dp</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import com.pspdfkit.ui.inspector.annotation.AnnotationEditingInspectorController
import com.pspdfkit.ui.inspector.annotation.DefaultAnnotationCreationInspectorController
import com.pspdfkit.ui.inspector.annotation.DefaultAnnotationEditingInspectorController
import com.pspdfkit.ui.inspector.views.BorderStylePreset
import com.pspdfkit.ui.note.AnnotationNoteHinter
import com.pspdfkit.ui.special_mode.controller.AnnotationCreationController
import com.pspdfkit.ui.special_mode.controller.AnnotationEditingController
import com.pspdfkit.ui.special_mode.controller.AnnotationSelectionController
Expand All @@ -80,6 +81,7 @@ import kotlinx.coroutines.Job
import okhttp3.ResponseBody
import java.io.File
import java.util.*
import kotlin.jvm.Throws

@SuppressLint("ViewConstructor")
abstract class PdfSubmissionView(context: Context) : FrameLayout(context), AnnotationManager.OnAnnotationCreationModeChangeListener, AnnotationManager.OnAnnotationEditingModeChangeListener {
Expand All @@ -88,6 +90,7 @@ abstract class PdfSubmissionView(context: Context) : FrameLayout(context), Annot
protected lateinit var apiValues: ApiValues
protected val commentRepliesHashMap: HashMap<String, ArrayList<CanvaDocAnnotation>> = HashMap()
protected var pdfFragment: PdfFragment? = null
protected var noteHinter: AnnotationNoteHinter? = null
protected val supportFragmentManager: FragmentManager = (context as AppCompatActivity).supportFragmentManager

private val pdfConfiguration: PdfConfiguration = PdfConfiguration.Builder()
Expand Down Expand Up @@ -250,6 +253,12 @@ abstract class PdfSubmissionView(context: Context) : FrameLayout(context), Annot
// Create new comment reply for this annotation.
if (text.isValid()) {
createCommentAnnotation(currentAnnotation.annotationId, currentAnnotation.page, text)
// Add contents to the current annotation so we can add an indicator
if(currentAnnotation.annotationType != CanvaDocAnnotation.AnnotationType.TEXT && currentAnnotation.annotationType != CanvaDocAnnotation.AnnotationType.FREE_TEXT) {
currentPdfAnnotation.contents = "comment"
noteHinter?.notifyDrawablesChanged()
pdfFragment?.notifyAnnotationHasChanged(currentPdfAnnotation)
}
}
}.show(supportFragmentManager, AnnotationCommentDialog::class.java.simpleName)
} else {
Expand All @@ -270,6 +279,9 @@ abstract class PdfSubmissionView(context: Context) : FrameLayout(context), Annot
pdfFragment?.addOnAnnotationCreationModeChangeListener(this)
pdfFragment?.addOnAnnotationEditingModeChangeListener(this)

noteHinter = AnnotationNoteHinter(context)
pdfFragment?.addDrawableProvider(noteHinter!!)

if (docSession.annotationMetadata?.canWrite() == true) {
// push the pdf viewing screen under the toolbar
pdfFragment?.setInsets(0, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60f, context.resources.displayMetrics).toInt(), 0, 0)
Expand Down Expand Up @@ -332,8 +344,10 @@ abstract class PdfSubmissionView(context: Context) : FrameLayout(context), Annot
// We don't want to trigger the annotation events here, so unregister and re-register after
pdfFragment?.document?.annotationProvider?.removeOnAnnotationUpdatedListener(mAnnotationUpdateListener)

// Grab all the annotations
for (item in annotations.data) {
// Grab all the annotations and sort them by type (descending).
// This will result in all of the comments being iterated over first as the COMMENT_REPLY type is last in the AnnotationType enum.
val sortedAnnotationList = annotations.data.sortedByDescending { it.annotationType }
for (item in sortedAnnotationList) {
if (item.annotationType == CanvaDocAnnotation.AnnotationType.COMMENT_REPLY) {
// Grab the annotation comments and store them to be displayed later when user selects annotation
if (commentRepliesHashMap.containsKey(item.inReplyTo)) {
Expand All @@ -355,13 +369,20 @@ abstract class PdfSubmissionView(context: Context) : FrameLayout(context), Annot
}
}

if(commentRepliesHashMap.containsKey(annotation.name)
&& (item.annotationType != CanvaDocAnnotation.AnnotationType.TEXT && item.annotationType != CanvaDocAnnotation.AnnotationType.FREE_TEXT)) {
annotation.contents = "comment"
}

pdfFragment?.document?.annotationProvider?.addAnnotationToPage(annotation)
pdfFragment?.notifyAnnotationHasChanged(annotation)
}
}
}

}

noteHinter?.notifyDrawablesChanged()
pdfFragment?.document?.annotationProvider?.addOnAnnotationUpdatedListener(mAnnotationUpdateListener)
pdfFragment?.addOnAnnotationSelectedListener(annotationSelectedListener)
pdfFragment?.addOnAnnotationDeselectedListener(mAnnotationDeselectedListener)
Expand Down Expand Up @@ -583,6 +604,7 @@ abstract class PdfSubmissionView(context: Context) : FrameLayout(context), Annot
// If it is not found, don't hit the server (it will fail)
if (!annotation.name.isNullOrEmpty())
awaitApi<ResponseBody> { CanvaDocsManager.deleteAnnotation(apiValues.sessionId, annotation.name!!, apiValues.canvaDocsDomain, it) }
noteHinter?.notifyDrawablesChanged()
} catch {
// Show general error, make more specific in the future?
toast(R.string.errorOccurred)
Expand Down Expand Up @@ -614,7 +636,7 @@ abstract class PdfSubmissionView(context: Context) : FrameLayout(context), Annot
}

private fun setupAnnotationCreationList(): MutableList<AnnotationTool> {
return mutableListOf(AnnotationTool.INK, AnnotationTool.HIGHLIGHT, AnnotationTool.STRIKEOUT, AnnotationTool.SQUARE, AnnotationTool.STAMP, AnnotationTool.FREETEXT, AnnotationTool.ERASER)
return mutableListOf(AnnotationTool.INK, AnnotationTool.HIGHLIGHT, AnnotationTool.STRIKEOUT, AnnotationTool.SQUARE, AnnotationTool.STAMP, AnnotationTool.FREETEXT, AnnotationTool.ERASER, AnnotationTool.NOTE)
}

private fun setupAnnotationEditList(): MutableList<AnnotationType> {
Expand Down Expand Up @@ -707,7 +729,7 @@ abstract class PdfSubmissionView(context: Context) : FrameLayout(context), Annot
.setSupportedProperties(EnumSet.of(AnnotationProperty.COLOR))
.setDefaultColor(ContextCompat.getColor(context, R.color.blueAnnotation))
.setDefaultThickness(2f)
.setDefaultAlpha(100f)
.setDefaultAlpha(1f)
.setDefaultFillColor(ContextCompat.getColor(context, R.color.transparent))
.setDefaultBorderStylePreset(BorderStylePreset.SOLID)
.setZIndexEditingEnabled(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 - present Instructure, Inc.
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, version 3 of the License.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12dp"
android:height="12dp"
android:viewportWidth="12"
android:viewportHeight="12">
<path
android:fillColor="#2D3B45"
android:strokeWidth="1"
android:pathData="M7.33333333,6 L7.80473785,6 L9.33333333,7.52859548 L9.33333333,6 L10.6666667,6
L10.6666667,1.33333333 L4.66666667,1.33333333 L4.66666667,2.66666667
L4,2.66666667 L4,0.666666667 L11.3333333,0.666666667 L11.3333333,6.66666667
L10,6.66666667 L10,9.13807119 L7.52859548,6.66666667 L7.33333333,6.66666667
L7.33333333,9.33333333 L4.47140452,9.33333333 L2,11.8047379 L2,9.33333333
L0,9.33333333 L0,3.33333333 L7.33333333,3.33333333 L7.33333333,6 Z
M6.66666667,8.66666667 L6.66666667,4 L0.666666667,4 L0.666666667,8.66666667
L2.66666667,8.66666667 L2.66666667,10.1952621 L4.19526215,8.66666667
L6.66666667,8.66666667 Z M2,6 L2,5.33333333 L5.33333333,5.33333333 L5.33333333,6
L2,6 Z M2,7.33333333 L2,6.66666667 L4,6.66666667 L4,7.33333333 L2,7.33333333 Z" />
</vector>

0 comments on commit 5cd48cb

Please sign in to comment.