Revision: 2800
http://sourceforge.net/p/swingme/code/2800
Author: yuranet
Date: 2024-10-13 09:02:51 +0000 (Sun, 13 Oct 2024)
Log Message:
-----------
support lastModified
Modified Paths:
--------------
AndroidME/src_Android/net/yura/android/io/StorageAccessConnection.java
Modified: AndroidME/src_Android/net/yura/android/io/StorageAccessConnection.java
===================================================================
--- AndroidME/src_Android/net/yura/android/io/StorageAccessConnection.java 2024-10-13 01:06:41 UTC (rev 2799)
+++ AndroidME/src_Android/net/yura/android/io/StorageAccessConnection.java 2024-10-13 09:02:51 UTC (rev 2800)
@@ -23,7 +23,7 @@
public class StorageAccessConnection implements FileConnection {
private String uri;
- private transient Uri documentUri;
+ private Uri documentUri;
public StorageAccessConnection(String uri) {
setFileConnection(uri);
@@ -32,6 +32,7 @@
@Override
public void setFileConnection(String fileName) {
uri = fileName;
+ documentUri = getAndroidDocumentUri();
}
@Override
@@ -88,9 +89,8 @@
@Override
public String getName() {
- Uri uri = getAndroidDocumentUri();
- if (uri != null) {
- Cursor cursor = AndroidMeApp.getIntance().getContentResolver().query(uri, null, null, null, null, null);
+ if (documentUri != null) {
+ Cursor cursor = AndroidMeApp.getIntance().getContentResolver().query(documentUri, null, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
@@ -102,14 +102,13 @@
}
}
// fall back to taking the last segment from the url
- return this.uri.substring(this.uri.lastIndexOf('/') + 1);
+ return uri.substring(uri.lastIndexOf('/') + 1);
}
@Override
public long fileSize() throws IOException {
- Uri uri = getAndroidDocumentUri();
- if (uri != null) {
- Cursor cursor = AndroidMeApp.getIntance().getContentResolver().query(uri, null, null, null, null, null);
+ if (documentUri != null) {
+ Cursor cursor = AndroidMeApp.getIntance().getContentResolver().query(documentUri, null, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
@@ -128,8 +127,7 @@
*/
@Override
public boolean exists() {
- Uri uri = getAndroidDocumentUri();
- return uri != null;
+ return documentUri != null;
}
/**
@@ -144,12 +142,11 @@
* @see androidx.documentfile.provider.DocumentsContractApi19#queryForString(Context, Uri, String, String)
*/
private String getMimeType() {
- Uri self = getAndroidDocumentUri();
- if (self != null) {
- final ContentResolver resolver = AndroidMeApp.getIntance().getContentResolver();
+ if (documentUri != null) {
+ ContentResolver resolver = AndroidMeApp.getIntance().getContentResolver();
Cursor c = null;
try {
- c = resolver.query(self, new String[]{DocumentsContract.Document.COLUMN_MIME_TYPE}, null, null, null);
+ c = resolver.query(documentUri, new String[]{DocumentsContract.Document.COLUMN_MIME_TYPE}, null, null, null);
if (c.moveToFirst() && !c.isNull(0)) {
String mimeType = c.getString(0);
return mimeType;
@@ -163,6 +160,26 @@
}
/**
+ * @see androidx.documentfile.provider.DocumentsContractApi19#queryForLong(Context, Uri, String, long)
+ */
+ @Override
+ public long lastModified() {
+ if (documentUri != null) {
+ final ContentResolver resolver = AndroidMeApp.getIntance().getContentResolver();
+ Cursor c = null;
+ try {
+ c = resolver.query(documentUri, new String[]{DocumentsContract.Document.COLUMN_LAST_MODIFIED}, null, null, null);
+ if (c.moveToFirst() && !c.isNull(0)) {
+ return c.getLong(0);
+ }
+ } finally {
+ close(c);
+ }
+ }
+ return 0L;
+ }
+
+ /**
* @see androidx.documentfile.provider.DocumentsContractApi19#closeQuietly(AutoCloseable)
*/
private static void close(Cursor cursor) {
@@ -184,10 +201,9 @@
@Override
public Enumeration list(String filter, boolean includeHidden) throws IOException {
// TODO support filter and hidden files
- Uri parentDocumentUri = getAndroidDocumentUri();
- if (parentDocumentUri == null) { return EMPTY_VECTOR.elements(); }
+ if (documentUri == null) { return EMPTY_VECTOR.elements(); }
- Uri childDocumentsUri = DocumentsContract.buildChildDocumentsUriUsingTree(parentDocumentUri, DocumentsContract.getDocumentId(parentDocumentUri));
+ Uri childDocumentsUri = DocumentsContract.buildChildDocumentsUriUsingTree(documentUri, DocumentsContract.getDocumentId(documentUri));
ContentResolver contentResolver = AndroidMeApp.getIntance().getContentResolver();
Cursor c = contentResolver.query(childDocumentsUri, new String[]{DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME, DocumentsContract.Document.COLUMN_MIME_TYPE}, null, null, null);
return new CursorEnumeration(c);
@@ -235,12 +251,12 @@
@Override
public InputStream openInputStream() throws IOException {
- return AndroidMeApp.getIntance().getContentResolver().openInputStream(getAndroidDocumentUri());
+ return AndroidMeApp.getIntance().getContentResolver().openInputStream(documentUri);
}
@Override
public OutputStream openOutputStream() throws IOException {
- return AndroidMeApp.getIntance().getContentResolver().openOutputStream(getAndroidDocumentUri());
+ return AndroidMeApp.getIntance().getContentResolver().openOutputStream(documentUri);
}
@@ -261,6 +277,7 @@
@Override
public boolean isHidden() {
+ // COLUMN_FLAGS
throw new UnsupportedOperationException();
}
@@ -270,11 +287,6 @@
}
@Override
- public long lastModified() {
- throw new UnsupportedOperationException();
- }
-
- @Override
public long availableSize() {
throw new UnsupportedOperationException();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|