mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-10-31 19:44:20 +00:00
DocumentsProvider refreshing after changing files (#197)
* DocumentsProvider refreshing after changing files * Add a flags for notifyChange function
This commit is contained in:
parent
41b840d13f
commit
5bd0dcd564
|
@ -1,11 +1,14 @@
|
||||||
package io.github.doukutsu_rs;
|
package io.github.doukutsu_rs;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.database.MatrixCursor.RowBuilder;
|
import android.database.MatrixCursor.RowBuilder;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.CancellationSignal;
|
import android.os.CancellationSignal;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.provider.DocumentsContract;
|
||||||
import android.provider.DocumentsContract.Document;
|
import android.provider.DocumentsContract.Document;
|
||||||
import android.provider.DocumentsContract.Root;
|
import android.provider.DocumentsContract.Root;
|
||||||
import android.provider.DocumentsProvider;
|
import android.provider.DocumentsProvider;
|
||||||
|
@ -98,7 +101,9 @@ public class DoukutsuDocumentsProvider extends DocumentsProvider {
|
||||||
pushFile(result, file);
|
pushFile(result, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.setNotificationUri(getContext().getContentResolver(), DocumentsContract.buildDocumentUri(BuildConfig.DOCUMENTS_AUTHORITY, parentDocumentId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +142,16 @@ public class DoukutsuDocumentsProvider extends DocumentsProvider {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileNotFoundException("Couldn't create file: " + e.getMessage());
|
throw new FileNotFoundException("Couldn't create file: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uri uri = DocumentsContract.buildDocumentUri(BuildConfig.DOCUMENTS_AUTHORITY, file.getParent());
|
||||||
|
|
||||||
|
if (SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
getContext().getContentResolver().notifyChange(uri, null, ContentResolver.NOTIFY_INSERT);
|
||||||
|
} else {
|
||||||
|
getContext().getContentResolver().notifyChange(uri, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return file.getAbsolutePath();
|
return file.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,8 +164,15 @@ public class DoukutsuDocumentsProvider extends DocumentsProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteRecursive(file);
|
deleteRecursive(file);
|
||||||
// todo refresh this shit
|
|
||||||
// getContext().getContentResolver().refresh()
|
|
||||||
|
Uri uri = DocumentsContract.buildDocumentUri(BuildConfig.DOCUMENTS_AUTHORITY, file.getParent());
|
||||||
|
|
||||||
|
if (SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
getContext().getContentResolver().notifyChange(uri, null, ContentResolver.NOTIFY_DELETE);
|
||||||
|
} else {
|
||||||
|
getContext().getContentResolver().notifyChange(uri, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -201,6 +222,15 @@ public class DoukutsuDocumentsProvider extends DocumentsProvider {
|
||||||
throw new FileNotFoundException(e.getMessage());
|
throw new FileNotFoundException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Uri uri = DocumentsContract.buildDocumentUri(BuildConfig.DOCUMENTS_AUTHORITY, file.getParent());
|
||||||
|
|
||||||
|
if (SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
getContext().getContentResolver().notifyChange(uri, null, ContentResolver.NOTIFY_UPDATE);
|
||||||
|
} else {
|
||||||
|
getContext().getContentResolver().notifyChange(uri, null);
|
||||||
|
}
|
||||||
|
|
||||||
return newPath.getAbsolutePath();
|
return newPath.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue