Skip to content

Commit

Permalink
Fix Permissions Bug preventing application from starting
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan01 committed May 20, 2020
1 parent ffef00f commit a45c11e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions app/src/main/java/wlfs/largefilesplitter/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -671,7 +672,7 @@ public void onClick(DialogInterface dialog, int which) {
System.exit(-1);
}
})
.create().show();
.show();
}

private String getExtension(String fileName){
Expand Down

0 comments on commit a45c11e

Please sign in to comment.