Skip to content

Commit

Permalink
'minor_fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
Swati4star committed May 18, 2023
1 parent 5d91f3a commit adfc80a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
minSdkVersion 21
multiDexEnabled true
targetSdkVersion 33
versionCode 108
versionName "8.8.1"
versionCode 109
versionName "9.0.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
import swati4star.createpdf.util.RemoveDuplicates;
import swati4star.createpdf.util.StringUtils;

public class RemoveDuplicatePagesFragment extends Fragment implements MergeFilesAdapter.OnClickListener,
FilesListAdapter.OnFileItemClickedListener, BottomSheetPopulate, OnPDFCreatedInterface, OnBackPressedInterface {
public class RemoveDuplicatePagesFragment extends Fragment
implements MergeFilesAdapter.OnClickListener, FilesListAdapter.OnFileItemClickedListener,
BottomSheetPopulate, OnPDFCreatedInterface, OnBackPressedInterface {

private static final int INTENT_REQUEST_PICKFILE_CODE = 10;
BottomSheetBehavior mSheetBehavior;
Expand Down Expand Up @@ -79,8 +80,7 @@ public class RemoveDuplicatePagesFragment extends Fragment implements MergeFiles
private MaterialDialog mMaterialDialog;

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootview = inflater.inflate(R.layout.fragment_remove_duplicate_pages, container, false);
ButterKnife.bind(this, rootview);
mSheetBehavior = BottomSheetBehavior.from(layoutBottomSheet);
Expand All @@ -102,30 +102,29 @@ void onViewFilesClick(View view) {
*/
@OnClick(R.id.selectFile)
public void showFileChooser() {
startActivityForResult(mFileUtils.getFileChooser(),
INTENT_REQUEST_PICKFILE_CODE);
startActivityForResult(mFileUtils.getFileChooser(), INTENT_REQUEST_PICKFILE_CODE);
}
// Refactor onActivityResult() method to handle possible NullPointerExceptions

// Refactor onActivityResult() method to handle possible NullPointerExceptions
// when accessing data.getData(). Added try-catch blocks to handle exceptions
// in a better way(imo) to prevent app crashes.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK || data == null || data.getData() == null) {
return;
}

if (requestCode == INTENT_REQUEST_PICKFILE_CODE) {
try {
// Attempt to get the real path of the selected file and update the UI
String path = RealPathUtil.getInstance().getRealPath(getContext(), data.getData());
setTextAndActivateButtons(path);
} catch (NullPointerException e) {
// If a NullPointerException occurs, log it to the console and continue
e.printStackTrace();
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK || data == null || data.getData() == null) {
return;
}

if (requestCode == INTENT_REQUEST_PICKFILE_CODE) {
try {
// Attempt to get the real path of the selected file and update the UI
String path = RealPathUtil.getInstance().getRealPath(getContext(), data.getData());
setTextAndActivateButtons(path);
} catch (NullPointerException e) {
// If a NullPointerException occurs, log it to the console and continue
e.printStackTrace();
}
}
}
}

//On click remove duplicate button
@OnClick(R.id.remove)
Expand All @@ -140,14 +139,12 @@ private void resetValues() {

private void setTextAndActivateButtons(String path) {
mPath = path;
mMorphButtonUtility.setTextAndActivateButtons(path,
selectFileButton, removeDuplicateButton);
mMorphButtonUtility.setTextAndActivateButtons(path, selectFileButton, removeDuplicateButton);
}

@Override
public void onPopulate(ArrayList<String> paths) {
CommonCodeUtils.getInstance().populateUtil(mActivity, paths,
this, mLayout, mLottieProgress, mRecyclerViewFiles);
CommonCodeUtils.getInstance().populateUtil(mActivity, paths, this, mLayout, mLottieProgress, mRecyclerViewFiles);
}

@Override
Expand Down Expand Up @@ -191,9 +188,9 @@ public void onPDFCreated(boolean isNewPdfCreated, String path) {
return;
}
new DatabaseHelper(mActivity).insertRecord(path, mActivity.getString(R.string.created));
StringUtils.getInstance().getSnackbarwithAction(mActivity, R.string.snackbar_duplicate_removed)
.setAction(R.string.snackbar_viewAction,
v -> mFileUtils.openFile(path, FileUtils.FileType.e_PDF)).show();
StringUtils.getInstance().getSnackbarwithAction(mActivity,
R.string.snackbar_duplicate_removed)
.setAction(R.string.snackbar_viewAction, v -> mFileUtils.openFile(path, FileUtils.FileType.e_PDF)).show();
viewPdfButton(path);
resetValues();
}
Expand All @@ -212,8 +209,6 @@ public boolean checkSheetBehaviour() {
* check runtime permissions for storage and camera
***/
private void getRuntimePermissions() {
PermissionsUtils.getInstance().requestRuntimePermissions(this,
WRITE_PERMISSIONS,
REQUEST_CODE_FOR_WRITE_PERMISSION);
PermissionsUtils.getInstance().requestRuntimePermissions(this, WRITE_PERMISSIONS, REQUEST_CODE_FOR_WRITE_PERMISSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static swati4star.createpdf.R.id.add_watermark_fav;
import static swati4star.createpdf.R.id.compress_pdf;
import static swati4star.createpdf.R.id.compress_pdf_fav;
import static swati4star.createpdf.R.id.excel_to_pdf;
import static swati4star.createpdf.R.id.excel_to_pdf_fav;
import static swati4star.createpdf.R.id.extract_images;
import static swati4star.createpdf.R.id.extract_images_fav;
Expand Down Expand Up @@ -84,7 +83,6 @@
import static swati4star.createpdf.R.id.view_history;
import static swati4star.createpdf.R.id.view_history_fav;
import static swati4star.createpdf.R.id.zip_to_pdf_fav;
import static swati4star.createpdf.R.string.qr_barcode_pdf;

import android.app.Activity;
import android.view.View;
Expand Down Expand Up @@ -193,9 +191,9 @@ public Map<Integer, HomePageItem> fillNavigationItemsMap(boolean homePageItems)
addFragmentPosition(homePageItems, R.id.images_to_pdf,
images_to_pdf_fav, nav_camera, ic_menu_camera, R.string.images_to_pdf);
addFragmentPosition(homePageItems, qr_barcode_to_pdf,
qr_barcode_to_pdf_fav, nav_qrcode, ic_qrcode_24dp, qr_barcode_pdf);
qr_barcode_to_pdf_fav, nav_qrcode, ic_qrcode_24dp, R.string.qr_barcode_pdf);
addFragmentPosition(homePageItems, R.id.excel_to_pdf,
excel_to_pdf_fav, nav_excel_to_pdf, ic_excel, excel_to_pdf);
excel_to_pdf_fav, nav_excel_to_pdf, ic_excel, R.string.excel_to_pdf);
addFragmentPosition(homePageItems, view_files, view_files_fav,
nav_gallery, ic_menu_gallery, R.string.viewFiles);
addFragmentPosition(homePageItems, rotate_pages, rotate_pages_fav,
Expand Down

0 comments on commit adfc80a

Please sign in to comment.