diff --git a/app/src/main/java/wlfs/largefilesplitter/MainActivity.java b/app/src/main/java/wlfs/largefilesplitter/MainActivity.java index f68f13c..030a670 100644 --- a/app/src/main/java/wlfs/largefilesplitter/MainActivity.java +++ b/app/src/main/java/wlfs/largefilesplitter/MainActivity.java @@ -391,19 +391,19 @@ protected void onCreate(Bundle savedInstanceState) { txt_dir = findViewById(R.id.txt_dir); pb = findViewById(R.id.pb); - if(!permissionRequired()){ + if(permissionGranted()){ File join_output_path = new File(JOIN_FILE_PATH); File split_output_path = new File(SPLIT_FILE_PATH); if(!join_output_path.exists()){ boolean success = join_output_path.mkdirs(); - String msg = success? "LFS directory made in " + EXTERNAL : + String msg = success? "LFS directory made in " + JOIN_FILE_PATH : "Unable to create LFS directory"; Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); if(!success)System.exit(1); } if(!split_output_path.exists()){ boolean success = split_output_path.mkdirs(); - String msg = success? "LFS directory made in " + EXTERNAL : + String msg = success? "LFS directory made in " + SPLIT_FILE_PATH : "Unable to create LFS directory"; Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); if(!success)System.exit(1); @@ -435,7 +435,10 @@ public void afterTextChanged(Editable s){} btn_split.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if(permissionRequired()) return; + if(!permissionGranted()) { + requestExternalStoragePermission(); + return; + } String path = txt_path.getText().toString(); if(path.equals("")){ Toast.makeText(MainActivity.this, @@ -451,7 +454,10 @@ public void onClick(View v) { btn_join.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if(permissionRequired()) return; + if(!permissionGranted()) { + requestExternalStoragePermission(); + return; + } final String path = txt_dir.getText().toString(); if(path.equals("")){ Toast.makeText(MainActivity.this, @@ -622,12 +628,7 @@ else if(bytes > KB){ return String.format(Locale.getDefault(),"%3.2f %s",sizeh,unit); } - private boolean permissionRequired(){ - if(ContextCompat.checkSelfPermission(MainActivity.this, WRITE_EXTERNAL_STORAGE) - == PackageManager.PERMISSION_GRANTED){ - return false; - } - else requestExternalStoragePermission(); + private boolean permissionGranted(){ return (ContextCompat.checkSelfPermission(MainActivity.this, WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED); } @@ -671,7 +672,7 @@ public void onClick(DialogInterface dialog, int which) { System.exit(-1); } }) - .create().show(); + .show(); } private String getExtension(String fileName){