HomeFunFragment.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  3. * <p>
  4. * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  5. * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  6. * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  7. * This notice may not be removed from this file.
  8. */
  9. package com.compdfkit.pdfviewer.home;
  10. import android.content.Intent;
  11. import android.net.Uri;
  12. import android.os.Bundle;
  13. import android.provider.DocumentsContract;
  14. import android.view.LayoutInflater;
  15. import android.view.View;
  16. import android.view.ViewGroup;
  17. import androidx.annotation.NonNull;
  18. import androidx.annotation.Nullable;
  19. import androidx.fragment.app.Fragment;
  20. import androidx.recyclerview.widget.LinearLayoutManager;
  21. import com.compdfkit.pdfviewer.MainActivity;
  22. import com.compdfkit.pdfviewer.R;
  23. import com.compdfkit.pdfviewer.databinding.FragmentHomeBinding;
  24. import com.compdfkit.pdfviewer.home.datas.FunDatas;
  25. import com.compdfkit.ui.utils.CPDFCommomUtils;
  26. public class HomeFunFragment extends Fragment {
  27. private CHomeFunListAdapter funListAdapter;
  28. private FragmentHomeBinding binding;
  29. @Nullable
  30. @Override
  31. public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  32. binding = FragmentHomeBinding.inflate(inflater, container, false);
  33. return binding.getRoot();
  34. }
  35. @Override
  36. public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  37. super.onViewCreated(view, savedInstanceState);
  38. initFunList();
  39. }
  40. private void initFunList() {
  41. funListAdapter = new CHomeFunListAdapter();
  42. funListAdapter.setList(FunDatas.getFunList(getContext()));
  43. binding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
  44. binding.recyclerView.setAdapter(funListAdapter);
  45. funListAdapter.setOnItemClickListener((adapter, view, position) -> {
  46. HomeFunBean homeFunBean = funListAdapter.list.get(position);
  47. if (homeFunBean.isHead()) {
  48. return;
  49. }
  50. switch (homeFunBean.getType()) {
  51. case SamplePDF:
  52. Intent intent = new Intent(getContext(), MainActivity.class);
  53. intent.putExtra(MainActivity.EXTRA_FILE_PATH, homeFunBean.getFilePath());
  54. startActivity(intent);
  55. break;
  56. case Viewer:
  57. case Annotations:
  58. case Forms:
  59. case Signature:
  60. case DocumentEditor:
  61. case ContentEditor:
  62. case Security:
  63. case Watermark:
  64. showDocumentListFragment(homeFunBean.getType());
  65. break;
  66. case Redaction:
  67. CPDFCommomUtils.gotoWebsite(getContext(), getString(R.string.tools_compdf_security_url), null);
  68. break;
  69. case CompareDocuments:
  70. CPDFCommomUtils.gotoWebsite(getContext(), getString(R.string.tools_compdf_compare_url), null);
  71. break;
  72. case Conversion:
  73. CPDFCommomUtils.gotoWebsite(getContext(), getString(R.string.tools_compdf_conversion_url), null);
  74. break;
  75. case Compress:
  76. CPDFCommomUtils.gotoWebsite(getContext(), getString(R.string.tools_contact_sales_url), null);
  77. break;
  78. case Measurement:
  79. CPDFCommomUtils.gotoWebsite(getContext(), getString(R.string.tools_contact_sales_url), null);
  80. break;
  81. default:
  82. break;
  83. }
  84. });
  85. }
  86. private void showDocumentListFragment(HomeFunBean.FunType funType) {
  87. getParentFragmentManager()
  88. .beginTransaction()
  89. .addToBackStack(null)
  90. .setCustomAnimations(R.anim.tools_slide_in_right, R.anim.tools_slide_out_left, R.anim.tools_slide_in_left, R.anim.tools_slide_out_right)
  91. .replace(R.id.fragment_content, DocumentListFragment.newInstance(funType), funType.name() + "_DocumentListFragment")
  92. .commit();
  93. }
  94. }