4848import swati4star .createpdf .util .RemoveDuplicates ;
4949import swati4star .createpdf .util .StringUtils ;
5050
51- public class RemoveDuplicatePagesFragment extends Fragment implements MergeFilesAdapter .OnClickListener ,
52- FilesListAdapter .OnFileItemClickedListener , BottomSheetPopulate , OnPDFCreatedInterface , OnBackPressedInterface {
51+ public class RemoveDuplicatePagesFragment extends Fragment
52+ implements MergeFilesAdapter .OnClickListener , FilesListAdapter .OnFileItemClickedListener ,
53+ BottomSheetPopulate , OnPDFCreatedInterface , OnBackPressedInterface {
5354
5455 private static final int INTENT_REQUEST_PICKFILE_CODE = 10 ;
5556 BottomSheetBehavior mSheetBehavior ;
@@ -79,8 +80,7 @@ public class RemoveDuplicatePagesFragment extends Fragment implements MergeFiles
7980 private MaterialDialog mMaterialDialog ;
8081
8182 @ Override
82- public View onCreateView (@ NonNull LayoutInflater inflater , ViewGroup container ,
83- Bundle savedInstanceState ) {
83+ public View onCreateView (@ NonNull LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
8484 View rootview = inflater .inflate (R .layout .fragment_remove_duplicate_pages , container , false );
8585 ButterKnife .bind (this , rootview );
8686 mSheetBehavior = BottomSheetBehavior .from (layoutBottomSheet );
@@ -102,30 +102,29 @@ void onViewFilesClick(View view) {
102102 */
103103 @ OnClick (R .id .selectFile )
104104 public void showFileChooser () {
105- startActivityForResult (mFileUtils .getFileChooser (),
106- INTENT_REQUEST_PICKFILE_CODE );
105+ startActivityForResult (mFileUtils .getFileChooser (), INTENT_REQUEST_PICKFILE_CODE );
107106 }
108-
109- // Refactor onActivityResult() method to handle possible NullPointerExceptions
107+
108+ // Refactor onActivityResult() method to handle possible NullPointerExceptions
110109// when accessing data.getData(). Added try-catch blocks to handle exceptions
111110// in a better way(imo) to prevent app crashes.
112- @ Override
113- public void onActivityResult (int requestCode , int resultCode , Intent data ) {
114- if (resultCode != RESULT_OK || data == null || data .getData () == null ) {
115- return ;
116- }
117-
118- if (requestCode == INTENT_REQUEST_PICKFILE_CODE ) {
119- try {
120- // Attempt to get the real path of the selected file and update the UI
121- String path = RealPathUtil .getInstance ().getRealPath (getContext (), data .getData ());
122- setTextAndActivateButtons (path );
123- } catch (NullPointerException e ) {
124- // If a NullPointerException occurs, log it to the console and continue
125- e .printStackTrace ();
111+ @ Override
112+ public void onActivityResult (int requestCode , int resultCode , Intent data ) {
113+ if (resultCode != RESULT_OK || data == null || data .getData () == null ) {
114+ return ;
115+ }
116+
117+ if (requestCode == INTENT_REQUEST_PICKFILE_CODE ) {
118+ try {
119+ // Attempt to get the real path of the selected file and update the UI
120+ String path = RealPathUtil .getInstance ().getRealPath (getContext (), data .getData ());
121+ setTextAndActivateButtons (path );
122+ } catch (NullPointerException e ) {
123+ // If a NullPointerException occurs, log it to the console and continue
124+ e .printStackTrace ();
125+ }
126126 }
127127 }
128- }
129128
130129 //On click remove duplicate button
131130 @ OnClick (R .id .remove )
@@ -140,14 +139,12 @@ private void resetValues() {
140139
141140 private void setTextAndActivateButtons (String path ) {
142141 mPath = path ;
143- mMorphButtonUtility .setTextAndActivateButtons (path ,
144- selectFileButton , removeDuplicateButton );
142+ mMorphButtonUtility .setTextAndActivateButtons (path , selectFileButton , removeDuplicateButton );
145143 }
146144
147145 @ Override
148146 public void onPopulate (ArrayList <String > paths ) {
149- CommonCodeUtils .getInstance ().populateUtil (mActivity , paths ,
150- this , mLayout , mLottieProgress , mRecyclerViewFiles );
147+ CommonCodeUtils .getInstance ().populateUtil (mActivity , paths , this , mLayout , mLottieProgress , mRecyclerViewFiles );
151148 }
152149
153150 @ Override
@@ -191,9 +188,9 @@ public void onPDFCreated(boolean isNewPdfCreated, String path) {
191188 return ;
192189 }
193190 new DatabaseHelper (mActivity ).insertRecord (path , mActivity .getString (R .string .created ));
194- StringUtils .getInstance ().getSnackbarwithAction (mActivity , R . string . snackbar_duplicate_removed )
195- . setAction ( R .string .snackbar_viewAction ,
196- v -> mFileUtils .openFile (path , FileUtils .FileType .e_PDF )).show ();
191+ StringUtils .getInstance ().getSnackbarwithAction (mActivity ,
192+ R .string .snackbar_duplicate_removed )
193+ . setAction ( R . string . snackbar_viewAction , v -> mFileUtils .openFile (path , FileUtils .FileType .e_PDF )).show ();
197194 viewPdfButton (path );
198195 resetValues ();
199196 }
@@ -212,8 +209,6 @@ public boolean checkSheetBehaviour() {
212209 * check runtime permissions for storage and camera
213210 ***/
214211 private void getRuntimePermissions () {
215- PermissionsUtils .getInstance ().requestRuntimePermissions (this ,
216- WRITE_PERMISSIONS ,
217- REQUEST_CODE_FOR_WRITE_PERMISSION );
212+ PermissionsUtils .getInstance ().requestRuntimePermissions (this , WRITE_PERMISSIONS , REQUEST_CODE_FOR_WRITE_PERMISSION );
218213 }
219214}
0 commit comments