+
+ /**
+ * Returns if the file/folder is shared by link or not
+ * @param path Path of the file/folder
+ * @return
+ */
+ public boolean isFileShareByLink(String path) {
+ Cursor c = getCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
+ OCFile file = null;
+ if (c.moveToFirst()) {
+ file = createFileInstance(c);
+ }
+ c.close();
+ return file.isShareByLink();
+ }
+
+ /**
+ * Returns the public link of the file/folder
+ * @param path Path of the file/folder
+ * @return
+ */
+ public String getFilePublicLink(String path) {
+ Cursor c = getCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
+ OCFile file = null;
+ if (c.moveToFirst()) {
+ file = createFileInstance(c);
+ }
+ c.close();
+ return file.getPublicLink();
+ }
+
+
+ // Methods for Share Files
+ public boolean saveShareFile(OCShare shareFile) {
+ boolean overriden = false;
+ ContentValues cv = new ContentValues();
+ cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, shareFile.getFileSource());
+ cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, shareFile.getItemSource());
+ cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, shareFile.getShareType().getValue());
+ cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, shareFile.getShareWith());
+ cv.put(ProviderTableMeta.OCSHARES_PATH, shareFile.getPath());
+ cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, shareFile.getPermissions());
+ cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, shareFile.getSharedDate());
+ cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, shareFile.getExpirationDate());
+ cv.put(ProviderTableMeta.OCSHARES_TOKEN, shareFile.getToken());
+ cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, shareFile.getSharedWithDisplayName());
+ cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, shareFile.isDirectory() ? 1 : 0);
+ cv.put(ProviderTableMeta.OCSHARES_USER_ID, shareFile.getUserId());
+ cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, shareFile.getIdRemoteShared());
+ cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
+
+ boolean samePath = fileShareExists(shareFile.getPath());
+ if (samePath ||
+ fileShareExists(shareFile.getId()) ) { // for renamed files; no more delete and create
+
+ OCShare oldFile = null;
+ if (samePath) {
+ oldFile = getShareFileByPath(shareFile.getPath());
+ shareFile.setId(oldFile.getId());
+ } else {
+ oldFile = getShareFileById(shareFile.getId());
+ }
+
+ overriden = true;
+ if (getContentResolver() != null) {
+ getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv,
+ ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(shareFile.getId()) });
+ } else {
+ try {
+ getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_SHARE,
+ cv, ProviderTableMeta._ID + "=?",
+ new String[] { String.valueOf(shareFile.getId()) });
+ } catch (RemoteException e) {
+ Log_OC.e(TAG,
+ "Fail to insert insert file to database "
+ + e.getMessage());
+ }
+ }
+ } else {
+ Uri result_uri = null;
+ if (getContentResolver() != null) {
+ result_uri = getContentResolver().insert(
+ ProviderTableMeta.CONTENT_URI_SHARE, cv);
+ } else {
+ try {
+ result_uri = getContentProviderClient().insert(
+ ProviderTableMeta.CONTENT_URI_SHARE, cv);
+ } catch (RemoteException e) {
+ Log_OC.e(TAG,
+ "Fail to insert insert file to database "
+ + e.getMessage());
+ }
+ }
+ if (result_uri != null) {
+ long new_id = Long.parseLong(result_uri.getPathSegments()
+ .get(1));
+ shareFile.setId(new_id);
+ }
+ }
+
+ return overriden;
+ }
+
+ private OCShare getShareFileById(long id) {
+ Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
+ OCShare share = null;
+ if (c.moveToFirst()) {
+ share = createShareInstance(c);
+ }
+ c.close();
+ return share;
+ }