11/**
2- * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
2+ * Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
33 * <p>
44 * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
55 * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
99
1010package com .compdfkit .tools .annotation .pdfannotationlist ;
1111
12+
1213import android .app .Activity ;
1314import android .content .Intent ;
1415import android .net .Uri ;
3738import com .compdfkit .tools .annotation .pdfannotationlist .dialog .CPDFReplyDetailsDialogFragment ;
3839import com .compdfkit .tools .common .basic .fragment .CBasicThemeFragment ;
3940import com .compdfkit .tools .common .interfaces .COnSetPDFDisplayPageIndexListener ;
41+ import com .compdfkit .tools .common .pdf .config .bota .CPDFBotaAnnotationMenu ;
42+ import com .compdfkit .tools .common .pdf .config .bota .CPDFBotaGlobalMenuItem ;
43+ import com .compdfkit .tools .common .pdf .config .bota .CPDFBotaItemMenu ;
4044import com .compdfkit .tools .common .utils .CFileUtils ;
4145import com .compdfkit .tools .common .utils .CLog ;
4246import com .compdfkit .tools .common .utils .CToastUtil ;
@@ -65,6 +69,8 @@ public class CPDFAnnotationListFragment extends CBasicThemeFragment {
6569
6670 private ProgressBar progressBar ;
6771
72+ private CPDFBotaAnnotationMenu annotationMenu = new CPDFBotaAnnotationMenu ();
73+
6874
6975 public static CPDFAnnotationListFragment newInstance () {
7076 return new CPDFAnnotationListFragment ();
@@ -109,6 +115,9 @@ public void initWithPDFView(CPDFViewCtrl pdfView) {
109115 this .pdfView = pdfView ;
110116 }
111117
118+ public void setAnnotationMenu (CPDFBotaAnnotationMenu annotationMenu ) {
119+ this .annotationMenu = annotationMenu ;
120+ }
112121
113122 @ Override
114123 protected int layoutId () {
@@ -125,7 +134,22 @@ protected void onCreateView(View rootView) {
125134 @ Override
126135 public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
127136 super .onViewCreated (view , savedInstanceState );
128- listAdapter = new CPDFAnnotListAdapter ();
137+ listAdapter = new CPDFAnnotListAdapter (false ,false ,false );
138+ if (annotationMenu != null && !annotationMenu .getItem ().isEmpty ()) {
139+ for (CPDFBotaItemMenu cpdfBotaItemMenu : annotationMenu .getItem ()) {
140+ switch (cpdfBotaItemMenu .getId ()) {
141+ case CPDFBotaAnnotationMenu .MENU_ID_REVIEW_STATUS :
142+ listAdapter .setShowReviewStatus (true );
143+ break ;
144+ case CPDFBotaAnnotationMenu .MENU_ID_MARKED_STATUS :
145+ listAdapter .setShowMarkedStatus (true );
146+ break ;
147+ case CPDFBotaAnnotationMenu .MENU_ID_MORE :
148+ listAdapter .setShowMoreMenu (true );
149+ break ;
150+ }
151+ }
152+ }
129153 updateAnnotationList ();
130154 listAdapter .addOnItemChildClickListener ((adapter , view1 , position ) -> {
131155 CPDFAnnotListItem item = adapter .list .get (position );
@@ -137,7 +161,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
137161 }
138162 }
139163 } else if (view1 .getId () == R .id .iv_review_status ) {
140- listAdapter .showReviewStatusMenu (getContext (), position , view1 );
164+ List <String > subMenus = annotationMenu .getReviewStatusMenu ().getSubMenus ();
165+ if (subMenus != null ){
166+ listAdapter .showReviewStatusMenu (getContext (), position , view1 , subMenus );
167+ }
141168 } else if (view1 .getId () == R .id .cb_marked_status ) {
142169 listAdapter .showMarkedStatusMenu (getContext (), position , view1 );
143170 } else if (view1 .getId () == R .id .iv_more ) {
@@ -183,29 +210,44 @@ public void updateAnnotationList(boolean showProgressBar) {
183210 *
184211 */
185212 public void showAnnotationMenu (View anchorView ) {
186- CPopupMenuWindow menuWindow = new CPopupMenuWindow (getContext ());
187- boolean hasAnnotations = !listAdapter .list .isEmpty ();
188- menuWindow .addItem (R .string .tools_import_annotations , v -> importAnnotFileLauncher .launch (CFileUtils .getIntent ("application/octet-stream" )));
189- menuWindow .addItem (R .string .tools_export_annotations ,hasAnnotations , v -> {
190- // Select the directory to export the annotation files
191- String dirPath = Environment .getExternalStorageDirectory ().getAbsolutePath ();
192- CFileDirectoryDialog directoryDialog = CFileDirectoryDialog .newInstance (dirPath , getString (R .string .tools_saving_path ), getString (R .string .tools_okay ));
193- directoryDialog .setSelectFolderListener (dir -> {
194- CPDFDocument document = pdfView .getCPdfReaderView ().getPDFDocument ();
195- boolean result = CPDFAnnotDatas .exportAnnotations (document , dir , CFileUtils .getFileNameNoExtension (document .getFileName ()));
196- if (result ) {
197- CToastUtil .showLongToast (getContext (), R .string .tools_export_success );
213+ if (annotationMenu != null && annotationMenu .getGlobal () != null ) {
214+ CPopupMenuWindow menuWindow = new CPopupMenuWindow (getContext ());
215+ boolean hasAnnotations = !listAdapter .list .isEmpty ();
216+
217+ for (CPDFBotaGlobalMenuItem cpdfBotaGlobalMenuItem : annotationMenu .getGlobal ()) {
218+ switch (cpdfBotaGlobalMenuItem .getId ()) {
219+ case CPDFBotaAnnotationMenu .GLOBAL_MENU_ID_IMPORT_ANNOTATION :
220+ menuWindow .addItem (R .string .tools_import_annotations , v -> importAnnotFileLauncher .launch (CFileUtils .getIntent ("application/octet-stream" )));
221+ break ;
222+ case CPDFBotaAnnotationMenu .GLOBAL_MENU_ID_EXPORT_ANNOTATION :
223+ menuWindow .addItem (R .string .tools_export_annotations ,hasAnnotations , v -> {
224+ // Select the directory to export the annotation files
225+ String dirPath = Environment .getExternalStorageDirectory ().getAbsolutePath ();
226+ CFileDirectoryDialog directoryDialog = CFileDirectoryDialog .newInstance (dirPath , getString (R .string .tools_saving_path ), getString (R .string .tools_okay ));
227+ directoryDialog .setSelectFolderListener (dir -> {
228+ CPDFDocument document = pdfView .getCPdfReaderView ().getPDFDocument ();
229+ boolean result = CPDFAnnotDatas .exportAnnotations (document , dir , CFileUtils .getFileNameNoExtension (document .getFileName ()));
230+ if (result ) {
231+ CToastUtil .showLongToast (getContext (), R .string .tools_export_success );
232+ }
233+ });
234+ directoryDialog .show (getChildFragmentManager (), "dirDialog" );
235+ });
236+ break ;
237+ case CPDFBotaAnnotationMenu .GLOBAL_MENU_ID_REMOVE_ALL_ANNOTATION :
238+ menuWindow .addItem (R .string .tools_delete_all_annotations , hasAnnotations , v -> deleteAllAnnotations ());
239+ break ;
240+ case CPDFBotaAnnotationMenu .GLOBAL_MENU_ID_REMOVE_ALL_REPLY :
241+ menuWindow .addItem (R .string .tools_delete_all_replies ,hasAnnotations , v -> {
242+ CPDFDocument document = pdfView .getCPdfReaderView ().getPDFDocument ();
243+ CPDFAnnotDatas .removeAllAnnotationReply (document );
244+ updateAnnotationList ();
245+ });
246+ break ;
198247 }
199- });
200- directoryDialog .show (getChildFragmentManager (), "dirDialog" );
201- });
202- menuWindow .addItem (R .string .tools_delete_all_annotations , hasAnnotations , v -> deleteAllAnnotations ());
203- menuWindow .addItem (R .string .tools_delete_all_replies ,hasAnnotations , v -> {
204- CPDFDocument document = pdfView .getCPdfReaderView ().getPDFDocument ();
205- CPDFAnnotDatas .removeAllAnnotationReply (document );
206- updateAnnotationList ();
207- });
208- menuWindow .showAsDropDown (anchorView );
248+ }
249+ menuWindow .showAsDropDown (anchorView );
250+ }
209251 }
210252
211253 /**
@@ -229,27 +271,40 @@ public void deleteAllAnnotations() {
229271 */
230272 private void showAnnotationMoreMenu (CPDFAnnotListItem item , int position , View anchorView ) {
231273 CPopupMenuWindow moreMenu = new CPopupMenuWindow (getContext ());
232- moreMenu .addItem (R .string .tools_add_a_new_reply , v -> {
233- CPDFEditReplyDialogFragment editReplyDialogFragment = CPDFEditReplyDialogFragment .addReply ();
234- editReplyDialogFragment .setReplyContentListener (content -> {
235- CPDFReplyAnnotation replyAnnotation = item .getAttr ().createReplyAnnotation ();
236- replyAnnotation .setTitle (pdfView .getCPDFConfiguration ().annotationsConfig .annotationAuthor );
237- replyAnnotation .setContent (content );
238- showReplyDetailsFragment (item , position );
239- });
240- editReplyDialogFragment .show (getChildFragmentManager (), "addReplyDialogFragment" );
241- });
242- moreMenu .addItem (R .string .tools_view_replies , v -> showReplyDetailsFragment (item , position ));
243- moreMenu .addItem (R .string .tools_delete_annotation , v -> {
244- boolean result = item .getAttr ().removeFromPage ();
245- if (result ) {
246- listAdapter .remove (position );
247- ArrayList <Integer > pages = new ArrayList <>();
248- pages .add (item .getPage ());
249- pdfView .getCPdfReaderView ().reloadPages (pages );
250- pdfView .getCPdfReaderView ().postDelayed (() -> updateAnnotationList (false ), 450 );
274+ List <String > subMenus = annotationMenu .getMoreMenu ().getSubMenus ();
275+ if (subMenus != null && !subMenus .isEmpty ()) {
276+ for (String menu : subMenus ) {
277+ switch (menu ) {
278+ case CPDFBotaAnnotationMenu .MORE_MENU_ID_ADD_REPLY :
279+ moreMenu .addItem (R .string .tools_add_a_new_reply , v -> {
280+ CPDFEditReplyDialogFragment editReplyDialogFragment = CPDFEditReplyDialogFragment .addReply ();
281+ editReplyDialogFragment .setReplyContentListener (content -> {
282+ CPDFReplyAnnotation replyAnnotation = item .getAttr ().createReplyAnnotation ();
283+ replyAnnotation .setTitle (pdfView .getCPDFConfiguration ().annotationsConfig .annotationAuthor );
284+ replyAnnotation .setContent (content );
285+ showReplyDetailsFragment (item , position );
286+ });
287+ editReplyDialogFragment .show (getChildFragmentManager (), "addReplyDialogFragment" );
288+ });
289+ break ;
290+ case CPDFBotaAnnotationMenu .MORE_MENU_ID_VIEW_REPLY :
291+ moreMenu .addItem (R .string .tools_view_replies , v -> showReplyDetailsFragment (item , position ));
292+ break ;
293+ case CPDFBotaAnnotationMenu .MORE_MENU_ID_DELETE :
294+ moreMenu .addItem (R .string .tools_delete_annotation , v -> {
295+ boolean result = item .getAttr ().removeFromPage ();
296+ if (result ) {
297+ listAdapter .remove (position );
298+ ArrayList <Integer > pages = new ArrayList <>();
299+ pages .add (item .getPage ());
300+ pdfView .getCPdfReaderView ().reloadPages (pages );
301+ pdfView .getCPdfReaderView ().postDelayed (() -> updateAnnotationList (false ), 450 );
302+ }
303+ });
304+ break ;
305+ }
251306 }
252- });
307+ }
253308 int [] windowPos = CDimensUtils .calculatePopWindowPos (anchorView , moreMenu .getContentView ());
254309 moreMenu .setAnimationStyle (R .style .PopupAnimation );
255310 moreMenu .showAtLocation (anchorView , Gravity .START | Gravity .TOP , windowPos [0 ], windowPos [1 ]);
0 commit comments