Ver código fonte

ComPDFKit Demo(Android) - 1.Outline列表以及跳转功能

liuxiaolong 1 ano atrás
pai
commit
5e6d793ae6

+ 101 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfbota/pdfoutline/CPDFOutlineDialogFragment.java

@@ -0,0 +1,101 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ * <p>
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.pdfbota.pdfoutline;
+
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.compdfkit.tools.R;
+import com.compdfkit.tools.pdfbota.pdfoutline.adapter.COutlineListAdapter;
+import com.compdfkit.tools.pdfbota.pdfoutline.bean.COutlineData;
+import com.compdfkit.tools.pdfbota.pdfoutline.interfaces.OnOutlineClickListener;
+import com.compdfkit.tools.utils.dialog.DialogFragmentUtil;
+import com.compdfkit.tools.utils.view.CToolBar;
+import com.google.android.material.bottomsheet.BottomSheetBehavior;
+import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
+
+import java.util.ArrayList;
+
+public class CPDFOutlineDialogFragment extends BottomSheetDialogFragment {
+
+    private RecyclerView rvOutlineRecyclerView;
+
+    private CToolBar toolBar;
+
+    private COutlineListAdapter outlineListAdapter;
+
+    private static final String EXTRA_OUTLINE_LIST = "outlineList";
+
+    private OnOutlineClickListener outlineCallback;
+
+    public static CPDFOutlineDialogFragment showCPDFOutlineDialogFragment(ArrayList<COutlineData> outlineList){
+        CPDFOutlineDialogFragment dialogFragment = new CPDFOutlineDialogFragment();
+        Bundle bundle = new Bundle();
+        bundle.putParcelableArrayList(EXTRA_OUTLINE_LIST, outlineList);
+        dialogFragment.setArguments(bundle);
+        return dialogFragment;
+    }
+
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
+        DialogFragmentUtil.setBottomSheetDialogFragmentFullScreen(getDialog(), behavior);
+    }
+
+    @Nullable
+    @Override
+    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+        View rootView = inflater.inflate(R.layout.tools_cpdf_outline_dialog_fragment, container, false);
+        rvOutlineRecyclerView = rootView.findViewById(R.id.rv_outline);
+        toolBar = rootView.findViewById(R.id.tool_bar);
+        toolBar.setBackBtnClickListener(v -> {
+            dismiss();
+        });
+        return rootView;
+    }
+
+    @Override
+    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+        outlineListAdapter = new COutlineListAdapter();
+        outlineListAdapter.setOutlineClickListener(outlineCallback);
+        rvOutlineRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+        rvOutlineRecyclerView.setAdapter(outlineListAdapter);
+        outlineListAdapter.setList(getOutlineData());
+    }
+
+
+    private ArrayList<COutlineData> getOutlineData(){
+        ArrayList<COutlineData> outlineList = new ArrayList<>();
+        if (getArguments() == null){
+            return outlineList;
+        }
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
+            outlineList = getArguments().getParcelableArrayList(EXTRA_OUTLINE_LIST, COutlineData.class);
+        }else {
+            outlineList = getArguments().getParcelableArrayList(EXTRA_OUTLINE_LIST);
+        }
+        return outlineList;
+    }
+
+    public void setOutlineClickListener(OnOutlineClickListener outlineClickListener){
+        this.outlineCallback = outlineClickListener;
+    }
+
+}

+ 111 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfbota/pdfoutline/adapter/COutlineListAdapter.java

@@ -0,0 +1,111 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ *
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.pdfbota.pdfoutline.adapter;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.appcompat.widget.AppCompatTextView;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.compdfkit.tools.R;
+import com.compdfkit.tools.pdfbota.pdfoutline.bean.COutlineData;
+import com.compdfkit.tools.pdfbota.pdfoutline.interfaces.OnOutlineClickListener;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+public class COutlineListAdapter extends RecyclerView.Adapter<COutlineListAdapter.OutlineItemViewHolder> {
+
+    private List<COutlineData> list = new ArrayList<>();
+
+    private OnOutlineClickListener outlineClickListener;
+    public void setList(ArrayList<COutlineData> data){
+        list.clear();
+        list.addAll(data);
+    }
+
+
+    @NonNull
+    @Override
+    public OutlineItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+
+        return new OutlineItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.tools_outline_list_item, parent, false));
+    }
+
+    @Override
+    public void onBindViewHolder(@NonNull OutlineItemViewHolder holder, int position) {
+        COutlineData item = list.get(position);
+        holder.tvItemPadding.setText(item.getPaddingStr());
+        holder.tvItemTitle.setText(item.getTitle());
+        holder.tvItemPageIndex.setText(String.valueOf(item.getPageIndex()));
+        holder.ivItemArrow.setVisibility(item.childOutlineIsEmpty() ? View.INVISIBLE : View.VISIBLE);
+        holder.ivItemArrow.setImageResource(item.isExpand() ? R.drawable.tools_ic_arrow_down : R.drawable.tools_ic_right);
+
+        holder.itemView.setOnClickListener(v -> {
+            if (item.childOutlineIsEmpty()){
+                if (outlineClickListener != null) {
+                    outlineClickListener.callback(item.getPageIndex());
+                }
+            }else {
+                if (item.isExpand()){
+                    collapseItem(item);
+                }else {
+                    expandItem(position, item);
+                }
+            }
+        });
+    }
+
+    private void expandItem(int startIndex, COutlineData item){
+        item.setExpand(true);
+        list.addAll(startIndex +1, item.getChildOutline());
+        notifyDataSetChanged();
+    }
+
+    private void collapseItem(COutlineData item){
+        item.setExpand(false);
+        Iterator<COutlineData> iterator = item.getChildOutline().iterator();
+        while (iterator.hasNext()){
+            list.remove(iterator.next());
+        }
+        notifyDataSetChanged();
+    }
+
+    @Override
+    public int getItemCount() {
+        return list.size();
+    }
+
+    class OutlineItemViewHolder extends RecyclerView.ViewHolder{
+        AppCompatTextView tvItemPadding;
+        AppCompatImageView ivItemArrow;
+        AppCompatTextView tvItemTitle;
+        AppCompatTextView tvItemPageIndex;
+
+        public OutlineItemViewHolder(@NonNull View itemView) {
+            super(itemView);
+            tvItemPadding = itemView.findViewById(R.id.tv_outline_item_padding);
+            ivItemArrow = itemView.findViewById(R.id.iv_outline_item_arrow);
+            tvItemTitle = itemView.findViewById(R.id.tv_outline_item_title);
+            tvItemPageIndex = itemView.findViewById(R.id.tv_outline_item_page);
+        }
+    }
+
+    public void setOutlineClickListener(OnOutlineClickListener outlineClickListener){
+        this.outlineClickListener = outlineClickListener;
+    }
+
+}

+ 123 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfbota/pdfoutline/bean/COutlineData.java

@@ -0,0 +1,123 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ *
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.pdfbota.pdfoutline.bean;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.ArrayList;
+
+
+public class COutlineData implements Parcelable {
+
+    private int level;
+
+    private int pageIndex;
+
+    private String title;
+
+    private ArrayList<COutlineData> childOutline;
+
+    private boolean isExpand;
+
+    public COutlineData(){}
+    public COutlineData(int level, String title, int pageIndex, ArrayList<COutlineData> childOutlineList){
+        this.level = level;
+        this.title = title;
+        this.pageIndex = pageIndex;
+        this.childOutline = childOutlineList;
+    }
+
+    protected COutlineData(Parcel in) {
+        level = in.readInt();
+        pageIndex = in.readInt();
+        title = in.readString();
+        childOutline = in.createTypedArrayList(COutlineData.CREATOR);
+        isExpand = in.readByte() != 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeInt(level);
+        dest.writeInt(pageIndex);
+        dest.writeString(title);
+        dest.writeTypedList(childOutline);
+        dest.writeByte((byte) (isExpand ? 1 : 0));
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    public static final Creator<COutlineData> CREATOR = new Creator<COutlineData>() {
+        @Override
+        public COutlineData createFromParcel(Parcel in) {
+            return new COutlineData(in);
+        }
+
+        @Override
+        public COutlineData[] newArray(int size) {
+            return new COutlineData[size];
+        }
+    };
+
+    public int getLevel() {
+        return level;
+    }
+
+    public void setLevel(int level) {
+        this.level = level;
+    }
+
+    public int getPageIndex() {
+        return pageIndex;
+    }
+
+    public void setPageIndex(int pageIndex) {
+        this.pageIndex = pageIndex;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public ArrayList<COutlineData> getChildOutline() {
+        return childOutline;
+    }
+
+    public void setChildOutline(ArrayList<COutlineData> childOutline) {
+        this.childOutline = childOutline;
+    }
+
+    public boolean isExpand() {
+        return isExpand;
+    }
+
+    public void setExpand(boolean expand) {
+        isExpand = expand;
+    }
+
+    public String getPaddingStr(){
+        StringBuilder builder = new StringBuilder();
+        for (int i = 0; i < level; i++) {
+            builder.append("  ");
+        }
+        return builder.toString();
+    }
+
+    public boolean childOutlineIsEmpty(){
+        return childOutline == null || childOutline.size() == 0;
+    }
+}

+ 74 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfbota/pdfoutline/data/CPDFOutlineDatas.java

@@ -0,0 +1,74 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ * <p>
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.pdfbota.pdfoutline.data;
+
+
+import com.compdfkit.core.document.CPDFOutline;
+import com.compdfkit.tools.pdfbota.pdfoutline.bean.COutlineData;
+import com.compdfkit.tools.pdfview.CPDFReaderView;
+
+import java.util.ArrayList;
+
+public class CPDFOutlineDatas {
+
+    /**
+     * Get the list of outlines for a PDF document
+     * @param cpdfReaderView
+     * @see COutlineData
+     * @return ArrayList COutlineData
+     */
+    public static ArrayList<COutlineData> getOutlineList(CPDFReaderView cpdfReaderView) {
+        // Retrieve the outline root from the PDF document and convert it to a list of COutlineData objects
+        return convertToCOutlineDataList(cpdfReaderView.getCPdfReaderView()
+                .getPDFDocument().getOutlineRoot().getChildList());
+    }
+
+    /**
+     * Recursively convert an array of CPDFOutline objects to an ArrayList of COutlineData objects
+     * @param outlines outline list data
+     */
+    private static ArrayList<COutlineData> convertToCOutlineDataList(CPDFOutline[] outlines) {
+        ArrayList<COutlineData> outlineDataList = new ArrayList<>();
+        for (CPDFOutline outline : outlines) {
+            // Convert the CPDFOutline object to a COutlineData object
+            COutlineData outlineData = convertToCOutlineData(outline);
+            // Only add the COutlineData object to the list if its level is 1
+            if (outlineData.getLevel() == 1) {
+                outlineDataList.add(outlineData);
+            }
+            // If the CPDFOutline object has child outlines, convert them to COutlineData objects and add them to the list
+            if (outline.getChildList() != null && outline.getChildList().length > 0) {
+                outlineDataList.addAll(convertToCOutlineDataList(outline.getChildList()));
+            }
+        }
+        return outlineDataList;
+    }
+
+    /**
+     * Convert a CPDFOutline object to a COutlineData object
+     */
+    private static COutlineData convertToCOutlineData(CPDFOutline outline) {
+        COutlineData outlineData = new COutlineData();
+        outlineData.setLevel(outline.getLevel());
+        outlineData.setPageIndex(outline.getDestination().getPageIndex());
+        outlineData.setTitle(outline.getTitle());
+        outlineData.setChildOutline(new ArrayList<>());
+
+        // If the CPDFOutline object has child outlines, convert them to COutlineData objects and add them to the list
+        if (outline.getChildList() != null && outline.getChildList().length > 0) {
+            for (CPDFOutline child : outline.getChildList()) {
+                outlineData.getChildOutline().add(convertToCOutlineData(child));
+            }
+        }
+
+        return outlineData;
+    }
+
+}

+ 19 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfbota/pdfoutline/interfaces/OnOutlineClickListener.java

@@ -0,0 +1,19 @@
+/**
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
+ *
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+ * This notice may not be removed from this file.
+ */
+
+package com.compdfkit.tools.pdfbota.pdfoutline.interfaces;
+
+
+public interface OnOutlineClickListener{
+    /**
+     *
+     * @param pageIndex
+     */
+    void callback(int pageIndex);
+}

+ 0 - 46
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfoutline/CPDFOutlineDialogFragment.java

@@ -1,46 +0,0 @@
-/**
- * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- * <p>
- * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- * This notice may not be removed from this file.
- */
-
-package com.compdfkit.tools.pdfoutline;
-
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import com.compdfkit.tools.R;
-import com.compdfkit.tools.utils.dialog.DialogFragmentUtil;
-import com.google.android.material.bottomsheet.BottomSheetBehavior;
-import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
-
-public class CPDFOutlineDialogFragment extends BottomSheetDialogFragment {
-
-    @Override
-    public void onStart() {
-        super.onStart();
-        BottomSheetBehavior<View> behavior = BottomSheetBehavior.from((View) getView().getParent());
-        DialogFragmentUtil.setBottomSheetDialogFragmentFullScreen(getDialog(), behavior);
-    }
-
-    @Nullable
-    @Override
-    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
-        return inflater.inflate(R.layout.tools_cpdf_outline_dialog_fragment, container, false);
-    }
-
-    @Override
-    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
-
-    }
-
-}

+ 4 - 0
compdfkit-tools/src/main/java/com/compdfkit/tools/pdfview/CPDFReaderView.java

@@ -70,5 +70,9 @@ public class CPDFReaderView extends FrameLayout {
         }
     }
 
+    public com.compdfkit.ui.reader.CPDFReaderView getCPdfReaderView(){
+        return cPdfReaderView;
+    }
+
 
 }

+ 5 - 0
compdfkit-tools/src/main/res/drawable/tools_ic_arrow_down.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#000000"
+    android:viewportHeight="24" android:viewportWidth="24"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="@android:color/white" android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6 1.41,-1.41z"/>
+</vector>

+ 5 - 0
compdfkit-tools/src/main/res/drawable/tools_ic_right.xml

@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#000000"
+    android:viewportHeight="24" android:viewportWidth="24"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="@android:color/white" android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>
+</vector>

+ 2 - 1
compdfkit-tools/src/main/res/layout/tools_cpdf_outline_dialog_fragment.xml

@@ -16,12 +16,13 @@
         app:layout_constraintEnd_toEndOf="parent"/>
 
     <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/rv_outline"
         android:layout_width="match_parent"
         app:layout_constraintTop_toBottomOf="@id/tool_bar"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
-        android:layout_height="300dp"/>
+        android:layout_height="0dp"/>
 
 
 

+ 61 - 0
compdfkit-tools/src/main/res/layout/tools_outline_list_item.xml

@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:paddingLeft="4dp"
+    android:paddingRight="4dp">
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:id="@+id/tv_outline_item_padding"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <androidx.appcompat.widget.AppCompatImageView
+        android:id="@+id/iv_outline_item_arrow"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:visibility="invisible"
+        tools:visibility="visible"
+        app:srcCompat="@drawable/tools_ic_right"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toEndOf="@+id/tv_outline_item_padding"
+        app:layout_constraintTop_toTopOf="parent"
+         />
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:id="@+id/tv_outline_item_title"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:ellipsize="end"
+        android:maxLines="1"
+        android:minLines="1"
+        android:paddingTop="12dp"
+        android:paddingBottom="12dp"
+        android:singleLine="true"
+        android:textColor="@android:color/black"
+        android:textSize="14sp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toEndOf="@+id/iv_outline_item_arrow"
+        app:layout_constraintEnd_toStartOf="@+id/tv_outline_item_page"
+        app:layout_constraintTop_toTopOf="parent"
+        tools:text="outline title" />
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:id="@+id/tv_outline_item_page"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="8dp"
+        android:gravity="center_vertical"
+        android:maxLines="1"
+        android:paddingStart="3dp"
+        tools:text="1"
+        android:textSize="12sp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 17 - 3
viewer-ctrl-demo/src/main/java/com/compdfkit/demo/viewer/MainActivity.java

@@ -6,9 +6,13 @@ import android.os.Bundle;
 import android.widget.Toast;
 
 import com.compdfkit.demo.viewer.databinding.ViewerActivityMainBinding;
-import com.compdfkit.tools.pdfoutline.CPDFOutlineDialogFragment;
+import com.compdfkit.tools.pdfbota.pdfoutline.CPDFOutlineDialogFragment;
+import com.compdfkit.tools.pdfbota.pdfoutline.bean.COutlineData;
+import com.compdfkit.tools.pdfbota.pdfoutline.data.CPDFOutlineDatas;
 import com.compdfkit.tools.task.CExtractAssetFileTask;
 
+import java.util.ArrayList;
+
 public class MainActivity extends AppCompatActivity {
 
     /**
@@ -37,8 +41,12 @@ public class MainActivity extends AppCompatActivity {
         });
         binding.pdfToolBar.setOutlineBtnClickListener(v -> {
             //open outline
-            Toast.makeText(this, "outline", Toast.LENGTH_SHORT).show();
-            CPDFOutlineDialogFragment cpdfOutlineDialogFragment = new CPDFOutlineDialogFragment();
+            ArrayList<COutlineData> outlineList = CPDFOutlineDatas.getOutlineList(binding.pdfReaderView);
+            CPDFOutlineDialogFragment cpdfOutlineDialogFragment = CPDFOutlineDialogFragment.showCPDFOutlineDialogFragment(outlineList);
+            cpdfOutlineDialogFragment.setOutlineClickListener(pageIndex -> {
+                binding.pdfReaderView.getCPdfReaderView().setDisplayPageIndex(pageIndex);
+                cpdfOutlineDialogFragment.dismiss();
+            });
             cpdfOutlineDialogFragment.show(getSupportFragmentManager(), "outline");
 
         });
@@ -48,4 +56,10 @@ public class MainActivity extends AppCompatActivity {
 
     }
 
+
+
+
+
+
+
 }