Browse Source

Rename files downloaded on Android

pull/8235/head
staphen 5 months ago committed by Anders Jenbo
parent
commit
c8e0eec80e
  1. 19
      android-project/app/src/main/java/org/diasurgical/devilutionx/DataActivity.java

19
android-project/app/src/main/java/org/diasurgical/devilutionx/DataActivity.java

@ -153,7 +153,9 @@ public class DataActivity extends Activity {
.setDescription(description)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
File file = fileManager.getFile(fileName);
// Download to a temp file which will be renamed later
// See: https://stackoverflow.com/a/48128014
File file = fileManager.getFile(fileName + "~");
Uri destination = Uri.fromFile(file);
request.setDestinationUri(destination);
@ -184,12 +186,21 @@ public class DataActivity extends Activity {
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(receivedID);
Cursor cur = mgr.query(query);
int index = cur.getColumnIndex(DownloadManager.COLUMN_STATUS);
int statusIndex = cur.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (cur.moveToFirst()) {
if (cur.getInt(index) == DownloadManager.STATUS_SUCCESSFUL) {
int status = cur.getInt(statusIndex);
if (status == DownloadManager.STATUS_SUCCESSFUL) {
// Rename temp file by removing the tilde
// See: https://stackoverflow.com/a/48128014
int titleIndex = cur.getColumnIndex(DownloadManager.COLUMN_TITLE);
String fileName = cur.getString(titleIndex);
File temp = fileManager.getFile(fileName + "~");
File file = fileManager.getFile(fileName);
temp.renameTo(file);
pendingDownloads--;
}
if (cur.getInt(index) == DownloadManager.STATUS_FAILED) {
if (status == DownloadManager.STATUS_FAILED) {
isDownloadingSpawn = false;
isDownloadingFonts = false;
isDownloadingTranslation = false;

Loading…
Cancel
Save