Skip to content

Commit

Permalink
- fix not working detection of already defined synced folders
Browse files Browse the repository at this point in the history
- delete not used (and wrong) function

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Oct 23, 2018
1 parent 1d1e4f9 commit 2f1e5e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ public SyncedFolder findByLocalPathAndAccount(String localPath, Account account)

SyncedFolder result = null;
Cursor cursor = mContentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
null,
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " == \"" + localPath + "\"" + " AND " +
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " == " + account.name,
null,
null
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
null,
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + "=? AND " +
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " =? ",
new String[]{localPath, account.name},
null
);

if (cursor != null && cursor.getCount() == 1) {
Expand All @@ -209,40 +209,6 @@ public SyncedFolder findByLocalPathAndAccount(String localPath, Account account)

}

/**
* find a synced folder by local path.
*
* @param localPath the local path of the local folder
* @return the synced folder if found, else null
*/
public SyncedFolder findByLocalPath(String localPath) {
SyncedFolder result = null;
Cursor cursor = mContentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
null,
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH + " == \"" + localPath + "\"",
null,
null
);

if (cursor != null && cursor.getCount() == 1) {
result = createSyncedFolderFromCursor(cursor);
} else {
if (cursor == null) {
Log_OC.e(TAG, "Sync folder db cursor for local path=" + localPath + " in NULL.");
} else {
Log_OC.e(TAG, cursor.getCount() + " items for local path=" + localPath
+ " available in sync folder db. Expected 1. Failed to update sync folder db.");
}
}

if (cursor != null) {
cursor.close();
}

return result;
}

/**
* Delete all synced folders for an account
*
Expand Down Expand Up @@ -342,14 +308,12 @@ public int updateSyncFolder(SyncedFolder syncedFolder) {

ContentValues cv = createContentValuesFromSyncedFolder(syncedFolder);

int result = mContentResolver.update(
return mContentResolver.update(
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
cv,
ProviderMeta.ProviderTableMeta._ID + "=?",
new String[]{String.valueOf(syncedFolder.getId())}
);

return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ protected Result onRunJob(@NonNull Params params) {
String arbitraryDataString;
MediaFoldersModel mediaFoldersModel;

List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 1,
null, true);
List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 1, null,
true);
List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 1, null, true);
List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 1, null, true);

List<String> imageMediaFolderPaths = new ArrayList<>();
List<String> videoMediaFolderPaths = new ArrayList<>();
Expand Down Expand Up @@ -109,8 +107,7 @@ protected Result onRunJob(@NonNull Params params) {

for (Account account : accountList) {
for (String imageMediaFolder : imageMediaFolderPaths) {
if (syncedFolderProvider.findByLocalPathAndAccount(imageMediaFolder,
account) == null) {
if (syncedFolderProvider.findByLocalPathAndAccount(imageMediaFolder, account) == null) {
sendNotification(String.format(context.getString(R.string.new_media_folder_detected),
context.getString(R.string.new_media_folder_photos)),
imageMediaFolder.substring(imageMediaFolder.lastIndexOf('/') + 1,
Expand All @@ -120,8 +117,7 @@ protected Result onRunJob(@NonNull Params params) {
}

for (String videoMediaFolder : videoMediaFolderPaths) {
if (syncedFolderProvider.findByLocalPathAndAccount(videoMediaFolder,
account) == null) {
if (syncedFolderProvider.findByLocalPathAndAccount(videoMediaFolder, account) == null) {
sendNotification(String.format(context.getString(R.string.new_media_folder_detected),
context.getString(R.string.new_media_folder_videos)),
videoMediaFolder.substring(videoMediaFolder.lastIndexOf('/') + 1,
Expand All @@ -134,14 +130,14 @@ protected Result onRunJob(@NonNull Params params) {

} else {
mediaFoldersModel = new MediaFoldersModel(imageMediaFolderPaths, videoMediaFolderPaths);
arbitraryDataProvider.storeOrUpdateKeyValue(ACCOUNT_NAME_GLOBAL, KEY_MEDIA_FOLDERS, gson.toJson(mediaFoldersModel));
arbitraryDataProvider.storeOrUpdateKeyValue(ACCOUNT_NAME_GLOBAL, KEY_MEDIA_FOLDERS,
gson.toJson(mediaFoldersModel));
}

return Result.SUCCESS;
}

private void sendNotification(String contentTitle, String subtitle, Account account,
String path, int type) {
private void sendNotification(String contentTitle, String subtitle, Account account, String path, int type) {
Context context = getContext();
Intent intent = new Intent(getContext(), SyncedFoldersActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Expand Down

0 comments on commit 2f1e5e0

Please sign in to comment.