use of com.orgzly.android.BookName in project orgzly-android by orgzly.
the class ContentRepo method renameBook.
@Override
public VersionedRook renameBook(Uri from, String name) throws IOException {
DocumentFile fromDocFile = DocumentFile.fromSingleUri(context, from);
BookName bookName = BookName.fromFileName(fromDocFile.getName());
String newFileName = BookName.fileName(name, bookName.getFormat());
/* Check if document already exists. */
DocumentFile existingFile = repoDocumentFile.findFile(newFileName);
if (existingFile != null) {
throw new IOException("File at " + existingFile.getUri() + " already exists");
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Uri newUri = DocumentsContract.renameDocument(context.getContentResolver(), from, newFileName);
long mtime = fromDocFile.lastModified();
String rev = String.valueOf(mtime);
return new VersionedRook(getUri(), newUri, rev, mtime);
} else {
/*
* This should never happen, unless the user downgraded
* and uses the same repo uri.
*/
throw new IOException("Renaming notebooks is not supported on your device " + "(requires at least Lollipop)");
}
}
use of com.orgzly.android.BookName in project orgzly-android by orgzly.
the class UriUtils method getUriForNewName.
/**
* Replaces the name part of the uri, leaving everything (including the extension) the same.
*/
public static Uri getUriForNewName(Uri uri, String name) {
BookName bookName = BookName.fromFileName(uri.getLastPathSegment());
BookName.Format format = bookName.getFormat();
String newFilename = BookName.fileName(name, format);
return // Old Uri without file name
UriUtils.dirUri(uri).buildUpon().appendPath(// New file name
newFilename).build();
}
Aggregations