Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AutoUpload notification #3173

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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