Get shares from Database (WIP)

This commit is contained in:
masensio 2015-10-19 09:16:19 +02:00 committed by David A. Velasco
parent 20b0ec8977
commit 72987c296f
2 changed files with 93 additions and 21 deletions

View file

@ -31,6 +31,7 @@ import java.util.Set;
import java.util.Vector;
import android.accounts.Account;
import android.content.ContentProvider;
import android.content.ContentProviderClient;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
@ -1335,6 +1336,7 @@ public class FileDataStorageManager {
operations = prepareRemoveSharesInFolder(folder, operations);
if (shares != null) {
Log_OC.d(TAG, "SHARES..............................................");
// prepare operations to insert or update files to save in the given folder
for (OCShare share : shares) {
ContentValues cv = new ContentValues();
@ -1359,9 +1361,25 @@ public class FileDataStorageManager {
// adding a new share resource
operations.add(
ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).
withValues(cv).
build()
/* withValue(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource()).
withValue(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource()).
withValue(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue()).
withValue(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith()).
withValue(ProviderTableMeta.OCSHARES_PATH, share.getPath()).
withValue(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions()).
withValue(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate()).
withValue(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate()).
withValue(ProviderTableMeta.OCSHARES_TOKEN, share.getToken()).
withValue(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
share.getSharedWithDisplayName()).
withValue(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0).
withValue(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId()).
withValue(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared()).
withValue(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name).*/
withValues(cv).
build()
);
Log_OC.d(TAG, "The VALUES are cv " + cv.toString());
//}
}
}
@ -1409,6 +1427,46 @@ public class FileDataStorageManager {
return preparedOperations;
}
public ArrayList<OCShare> getSharesWithForAFile(String filePath, String accountName){
// Condition
String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND "
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"+ "AND"
+ " (" + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? ) ";
String [] whereArgs = new String[]{ filePath, accountName ,
Integer.toString(ShareType.USER.getValue()),
Integer.toString(ShareType.GROUP.getValue()) };
Cursor c = null;
if (getContentResolver() != null) {
c = getContentResolver().query(
ProviderTableMeta.CONTENT_URI_SHARE,
null, where, whereArgs, null);
} else {
try {
c = getContentProviderClient().query(
ProviderTableMeta.CONTENT_URI_SHARE,
null, where, whereArgs, null);
} catch (RemoteException e) {
Log_OC.e(TAG, "Could not get list of shares with: " + e.getMessage());
c = null;
}
}
ArrayList<OCShare> shares = new ArrayList<>();
OCShare share = null;
if (c.moveToFirst()) {
do {
share = createShareInstance(c);
shares.add(share);
// }
} while (c.moveToNext());
}
c.close();
return shares;
}
public void triggerMediaScan(String path) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(path)));

View file

@ -206,13 +206,22 @@ public class ShareFileFragment extends Fragment
RemoteOperationResult result = null;
// Show loading
( (ShareActivity) getActivity()).showWaitingLoadDialog();
// TODO: Activate loading
// ( (ShareActivity) getActivity()).showWaitingLoadDialog();
// Get Users and Groups
GetShareWithUserAsyncTask getTask = new GetShareWithUserAsyncTask(this);
FileDataStorageManager fileDataStorageManager =
new FileDataStorageManager(mAccount, getActivity().getContentResolver());
Object[] params = { mFile, mAccount, fileDataStorageManager};
getTask.execute(params);
mShares = fileDataStorageManager.getSharesWithForAFile(mFile.getRemotePath(), mAccount.name);
// Object[] params = { mFile, mAccount, fileDataStorageManager};
// getTask.execute(params);
// // Remove loading
// ((ShareActivity) getActivity()).dismissWaitingLoadDialog();
// Update list of users/groups
updateListOfUserGroups();
}
@Override
@ -229,22 +238,7 @@ public class ShareFileFragment extends Fragment
}
// Update list of users/groups
mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(),
R.layout.share_user_item, mShares);
// Show data
TextView noShares = (TextView) getView().findViewById(R.id.shareNoUsers);
ListView usersList = (ListView) getView().findViewById(R.id.shareUsersList);
if (mShares.size() > 0) {
noShares.setVisibility(View.GONE);
usersList.setVisibility(View.VISIBLE);
usersList.setAdapter(mUserGroupsAdapter);
} else {
noShares.setVisibility(View.VISIBLE);
usersList.setVisibility(View.GONE);
}
updateListOfUserGroups();
} else {
Toast.makeText(getActivity(), result.getLogMessage(), Toast.LENGTH_SHORT).show();
@ -252,6 +246,26 @@ public class ShareFileFragment extends Fragment
}
private void updateListOfUserGroups(){
// Update list of users/groups
mUserGroupsAdapter = new ShareUserListAdapter(getActivity().getApplicationContext(),
R.layout.share_user_item, mShares);
// Show data
TextView noShares = (TextView) getView().findViewById(R.id.shareNoUsers);
ListView usersList = (ListView) getView().findViewById(R.id.shareUsersList);
if (mShares.size() > 0) {
noShares.setVisibility(View.GONE);
usersList.setVisibility(View.VISIBLE);
usersList.setAdapter(mUserGroupsAdapter);
} else {
noShares.setVisibility(View.VISIBLE);
usersList.setVisibility(View.GONE);
}
}
// TODO: review if it is necessary
/**
* This interface must be implemented by activities that contain this