more SAF implementation

* full support for Directory API (Android Lollipop or later)
* best effort to handle any kind errors (missing file, revoked permissions, etc) and recover the download
* implemented directory choosing
* fix download database version upgrading
* misc. cleanup
* do not release permission on the old save path (if the user change the download directory) under SAF api
This commit is contained in:
kapodamy 2019-04-09 18:38:34 -03:00
parent f6b32823ba
commit d00dc798f4
28 changed files with 946 additions and 589 deletions

View file

@ -1,6 +1,5 @@
package us.shandian.giga.get;
import android.net.Uri;
import android.support.annotation.NonNull;
import java.io.Serializable;
@ -36,15 +35,6 @@ public abstract class Mission implements Serializable {
*/
public StoredFileHelper storage;
/**
* get the target file on the storage
*
* @return File object
*/
public Uri getDownloadedFileUri() {
return storage.getUri();
}
/**
* Delete the downloaded file
*
@ -52,7 +42,7 @@ public abstract class Mission implements Serializable {
*/
public boolean delete() {
if (storage != null) return storage.delete();
return true;
return true;
}
/**
@ -65,6 +55,6 @@ public abstract class Mission implements Serializable {
public String toString() {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp);
return "[" + calendar.getTime().toString() + "] " + getDownloadedFileUri().getPath();
return "[" + calendar.getTime().toString() + "] " + (storage.isInvalid() ? storage.getName() : storage.getUri());
}
}