use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class ShareUserListAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.share_user_item, parent, false);
if (mShares != null && mShares.size() > position) {
OCShare share = mShares.get(position);
TextView userName = (TextView) view.findViewById(R.id.userOrGroupName);
ImageView iconView = (ImageView) view.findViewById(R.id.icon);
String name = share.getSharedWithDisplayName();
Drawable icon = getContext().getResources().getDrawable(R.drawable.ic_user);
if (share.getShareType() == ShareType.GROUP) {
name = getContext().getString(R.string.share_group_clarification, name);
icon = getContext().getResources().getDrawable(R.drawable.ic_group);
}
userName.setText(name);
iconView.setImageDrawable(icon);
/// bind listener to edit privileges
final ImageView editShareButton = (ImageView) view.findViewById(R.id.editShareButton);
editShareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.editShare(mShares.get(position));
}
});
/// bind listener to unshare
final ImageView unshareButton = (ImageView) view.findViewById(R.id.unshareButton);
unshareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.unshareButtonPressed(mShares.get(position));
}
});
}
return view;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class ShareActivity method onCreateShareViaLinkOperationFinish.
private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
updateFileFromDB();
// Create dialog to allow the user choose an app to send the link
Intent intentToShareLink = new Intent(Intent.ACTION_SEND);
String link = ((OCShare) (result.getData().get(0))).getShareLink();
intentToShareLink.putExtra(Intent.EXTRA_TEXT, link);
intentToShareLink.setType("text/plain");
String username = AccountUtils.getUsernameForAccount(getAccount());
if (username != null) {
intentToShareLink.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.subject_user_shared_with_you, username, getFile().getFileName()));
} else {
intentToShareLink.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.subject_shared_with_you, getFile().getFileName()));
}
String[] packagesToExclude = new String[] { getPackageName() };
DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude);
chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
} else {
// Detect Failure (403) --> maybe needs password
String password = operation.getPassword();
if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_FORBIDDEN && (password == null || password.length() == 0) && getCapabilities().getFilesSharingPublicEnabled().isUnknown()) {
// Was tried without password, but not sure that it's optional.
// Try with password before giving up; see also ShareFileFragment#OnShareViaLinkListener
ShareFileFragment shareFileFragment = getShareFileFragment();
if (shareFileFragment != null && shareFileFragment.isAdded()) {
// only if added to the view hierarchy!!
shareFileFragment.requestPasswordForShareViaLink(true);
}
} else {
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Snackbar.LENGTH_LONG);
snackbar.show();
}
}
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class FileDataStorageManager method getFirstShareByPathAndType.
/**
* Get first share bound to a file with a known path and given {@link ShareType}.
*
* @param path Path of the file.
* @param type Type of the share to get
* @param shareWith Target of the share. Ignored in type is {@link ShareType#PUBLIC_LINK}
* @return First {@OCShare} instance found in DB bound to the file in 'path'
*/
public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
Cursor c = null;
if (shareWith == null) {
shareWith = "";
}
String selection = ProviderTableMeta.OCSHARES_PATH + "=? AND " + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
if (!ShareType.PUBLIC_LINK.equals(type)) {
selection += " AND " + ProviderTableMeta.OCSHARES_SHARE_WITH + "=?";
}
String[] selectionArgs;
if (ShareType.PUBLIC_LINK.equals(type)) {
selectionArgs = new String[] { path, Integer.toString(type.getValue()), mAccount.name };
} else {
selectionArgs = new String[] { path, Integer.toString(type.getValue()), mAccount.name, shareWith };
}
if (getContentResolver() != null) {
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI_SHARE, null, selection, selectionArgs, null);
} else {
try {
c = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI_SHARE, null, selection, selectionArgs, null);
} catch (RemoteException e) {
Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
c = null;
}
}
OCShare share = null;
if (c != null) {
if (c.moveToFirst()) {
share = createShareInstance(c);
}
c.close();
}
return share;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class FileDataStorageManager method prepareInsertShares.
/**
* Prepare operations to insert or update files to save in the given folder
* @param shares List of shares to insert
* @param operations List of operations
* @return
*/
private ArrayList<ContentProviderOperation> prepareInsertShares(ArrayList<OCShare> shares, ArrayList<ContentProviderOperation> operations) {
if (shares != null) {
// prepare operations to insert or update files to save in the given folder
for (OCShare share : shares) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource());
cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue());
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith());
cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath());
cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions());
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
// adding a new share resource
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).build());
}
}
return operations;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class FileDataStorageManager method createShareInstance.
private OCShare createShareInstance(Cursor c) {
OCShare share = null;
if (c != null) {
share = new OCShare(c.getString(c.getColumnIndex(ProviderTableMeta.OCSHARES_PATH)));
share.setId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
share.setFileSource(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_ITEM_SOURCE)));
share.setShareType(ShareType.fromValue(c.getInt(c.getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_TYPE))));
share.setShareWith(c.getString(c.getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_WITH)));
share.setPermissions(c.getInt(c.getColumnIndex(ProviderTableMeta.OCSHARES_PERMISSIONS)));
share.setSharedDate(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_SHARED_DATE)));
share.setExpirationDate(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_EXPIRATION_DATE)));
share.setToken(c.getString(c.getColumnIndex(ProviderTableMeta.OCSHARES_TOKEN)));
share.setSharedWithDisplayName(c.getString(c.getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME)));
share.setIsFolder(c.getInt(c.getColumnIndex(ProviderTableMeta.OCSHARES_IS_DIRECTORY)) == 1);
share.setUserId(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_USER_ID)));
share.setIdRemoteShared(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED)));
}
return share;
}
Aggregations