|
@ -632,10 +632,10 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
//-------------------------------------------BOOKMARKS END------------------------------------------
|
|
|
//-------------------------------------------BOOKMARKS END------------------------------------------
|
|
|
|
|
|
|
|
|
//-------PERMS---------
|
|
|
//-------PERMS---------
|
|
|
private static final int PERMISSIONS_REQUEST_CODE = 69; |
|
|
private static final int DOWNLOAD_REQUEST_CODE = 69; //Arbitrary, application specific
|
|
|
|
|
|
|
|
|
//True if permissions are OK
|
|
|
//True if permissions are OK
|
|
|
private boolean checkPerms() { |
|
|
protected boolean checkPerms() { |
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { |
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { |
|
|
String[] PERMISSIONS_STORAGE = { |
|
|
String[] PERMISSIONS_STORAGE = { |
|
|
Manifest.permission.READ_EXTERNAL_STORAGE, |
|
|
Manifest.permission.READ_EXTERNAL_STORAGE, |
|
@ -648,13 +648,13 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Display popup for user to grant permission
|
|
|
//Display popup for user to grant permission
|
|
|
private void requestPerms() { //Runtime permissions request for devices with API >= 23
|
|
|
protected void requestPerms(int code) { //Runtime permissions request for devices with API >= 23
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { |
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { |
|
|
String[] PERMISSIONS_STORAGE = { |
|
|
String[] PERMISSIONS_STORAGE = { |
|
|
Manifest.permission.READ_EXTERNAL_STORAGE, |
|
|
Manifest.permission.READ_EXTERNAL_STORAGE, |
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}; |
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}; |
|
|
|
|
|
|
|
|
requestPermissions(PERMISSIONS_STORAGE, PERMISSIONS_REQUEST_CODE); |
|
|
requestPermissions(PERMISSIONS_STORAGE, code); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -663,8 +663,9 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
public void onRequestPermissionsResult(int permsRequestCode, @NonNull String[] permissions |
|
|
public void onRequestPermissionsResult(int permsRequestCode, @NonNull String[] permissions |
|
|
, @NonNull int[] grantResults) { |
|
|
, @NonNull int[] grantResults) { |
|
|
switch (permsRequestCode) { |
|
|
switch (permsRequestCode) { |
|
|
case PERMISSIONS_REQUEST_CODE: |
|
|
case DOWNLOAD_REQUEST_CODE: |
|
|
downloadFile(); |
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) |
|
|
|
|
|
prepareDownload(tempThmmyFile); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -678,16 +679,10 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
prepareDownload(thmmyFile); |
|
|
prepareDownload(thmmyFile); |
|
|
else { |
|
|
else { |
|
|
tempThmmyFile = thmmyFile; |
|
|
tempThmmyFile = thmmyFile; |
|
|
requestPerms(); |
|
|
requestPerms(DOWNLOAD_REQUEST_CODE); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Uses temp file - called after permission grant
|
|
|
|
|
|
private void downloadFile() { |
|
|
|
|
|
if (checkPerms()) |
|
|
|
|
|
prepareDownload(tempThmmyFile); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void prepareDownload(ThmmyFile thmmyFile) { |
|
|
private void prepareDownload(ThmmyFile thmmyFile) { |
|
|
String fileName = thmmyFile.getFilename(); |
|
|
String fileName = thmmyFile.getFilename(); |
|
|
if (FileUtils.fileNameExists(fileName)) |
|
|
if (FileUtils.fileNameExists(fileName)) |
|
@ -705,15 +700,8 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
Button cancelButton = view.findViewById(R.id.cancel); |
|
|
Button cancelButton = view.findViewById(R.id.cancel); |
|
|
Button openButton = view.findViewById(R.id.open); |
|
|
Button openButton = view.findViewById(R.id.open); |
|
|
Button downloadButton = view.findViewById(R.id.download); |
|
|
Button downloadButton = view.findViewById(R.id.download); |
|
|
cancelButton.setOnClickListener(new View.OnClickListener() { |
|
|
cancelButton.setOnClickListener(v -> dialog.dismiss()); |
|
|
@Override |
|
|
openButton.setOnClickListener(v -> { |
|
|
public void onClick(View v) { |
|
|
|
|
|
dialog.dismiss(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
openButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
dialog.dismiss(); |
|
|
dialog.dismiss(); |
|
|
try { |
|
|
try { |
|
|
String fileName = thmmyFile.getFilename(); |
|
|
String fileName = thmmyFile.getFilename(); |
|
@ -727,14 +715,10 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
Toast.makeText(getBaseContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(getBaseContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
downloadButton.setOnClickListener(new View.OnClickListener() { |
|
|
downloadButton.setOnClickListener(v -> { |
|
|
@Override |
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
dialog.dismiss(); |
|
|
dialog.dismiss(); |
|
|
DownloadHelper.enqueueDownload(thmmyFile); |
|
|
DownloadHelper.enqueueDownload(thmmyFile); |
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
dialog.show(); |
|
|
dialog.show(); |
|
|
} |
|
|
} |
|
|