From: David A. Velasco Date: Fri, 21 Aug 2015 08:36:42 +0000 (+0200) Subject: Added conflict icon to folders containing files with conflicts X-Git-Tag: oc-android-1.9^2~37^2~16 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/a2aa0479fc590a42b2167e5748d374f2df29dfad?ds=inline Added conflict icon to folders containing files with conflicts --- diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index ce3510d3..2c513c48 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -24,8 +24,10 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.Vector; import android.accounts.Account; @@ -1586,27 +1588,80 @@ public class FileDataStorageManager { } - public void saveConflict(long fileId, boolean inConflict) { + public void saveConflict(OCFile file, boolean inConflict) { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_IN_CONFLICT, inConflict); + int updated = 0; if (getContentResolver() != null) { - getContentResolver().update( + updated = getContentResolver().update( ProviderTableMeta.CONTENT_URI_FILE, cv, ProviderTableMeta._ID + "=?", - new String[] { String.valueOf(fileId)} + new String[] { String.valueOf(file.getFileId())} ); } else { try { - getContentProviderClient().update( + updated = getContentProviderClient().update( ProviderTableMeta.CONTENT_URI_FILE, cv, ProviderTableMeta._ID + "=?", - new String[]{String.valueOf(fileId)} + new String[]{String.valueOf(file.getFileId())} ); } catch (RemoteException e) { Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage()); } } + + Log_OC.d(TAG, "Number of files updated with CONFLICT: " + updated); + + if (updated > 0) { + if (inConflict) { + /// set conflict in all ancestor folders + + long parentId = file.getParentId(); + Set ancestorIds = new HashSet(); + while (parentId != FileDataStorageManager.ROOT_PARENT_ID) { + ancestorIds.add(Long.toString(parentId)); + parentId = getFileById(parentId).getParentId(); + } + + if (ancestorIds.size() > 0) { + StringBuffer whereBuffer = new StringBuffer(); + whereBuffer.append(ProviderTableMeta._ID).append(" IN ("); + for (int i = 0; i < ancestorIds.size() - 1; i++) { + whereBuffer.append("?,"); + } + whereBuffer.append("?"); + whereBuffer.append(")"); + + if (getContentResolver() != null) { + updated = getContentResolver().update( + ProviderTableMeta.CONTENT_URI_FILE, + cv, + whereBuffer.toString(), + ancestorIds.toArray(new String[]{}) + ); + } else { + try { + updated = getContentProviderClient().update( + ProviderTableMeta.CONTENT_URI_FILE, + cv, + whereBuffer.toString(), + ancestorIds.toArray(new String[]{}) + ); + } catch (RemoteException e) { + Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage()); + } + } + } // else file is ROOT folder, no parent to set in conflict + + } else { + /// TODO update conflict in ancestor folders + // (not directly unset; maybe there are more conflicts below them) + } + } + + Log_OC.d(TAG, "Number of parents updated with CONFLICT: " + updated); + } } diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index 045f9b23..1998181c 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -222,7 +222,7 @@ public class SynchronizeFileOperation extends SyncOperation { //if (!mLocalFile.getEtag().isEmpty() && localChanged && serverChanged) { if (localChanged && serverChanged) { result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); - getStorageManager().saveConflict(mLocalFile.getFileId(), true); + getStorageManager().saveConflict(mLocalFile, true); } else if (localChanged) { if (mSyncFileContents && mAllowUploads) { diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 2672926f..5a68c5bd 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -254,23 +254,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { localStateView.setVisibility(View.INVISIBLE); // default first - if (file.isFolder()) { - if ( //synchronizing - (opsBinder != null && - opsBinder.isSynchronizing(mAccount, file.getRemotePath())) || - // downloading - (downloaderBinder != null && - downloaderBinder.isDownloading(mAccount, file)) || - // uploading - (uploaderBinder != null && - uploaderBinder.isUploading(mAccount, file)) - ) { - - localStateView.setImageResource(R.drawable.synchronizing_file_indicator); - localStateView.setVisibility(View.VISIBLE); - } - - } else if ( //synchronizing + if ( //synchronizing opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath()) ) { @@ -281,14 +265,22 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file) ) { - localStateView.setImageResource(R.drawable.downloading_file_indicator); + localStateView.setImageResource( + file.isFolder() ? + R.drawable.synchronizing_file_indicator : + R.drawable.downloading_file_indicator + ); localStateView.setVisibility(View.VISIBLE); - } else if (//uploading + } else if ( //uploading uploaderBinder != null && uploaderBinder.isUploading(mAccount, file) ) { - localStateView.setImageResource(R.drawable.uploading_file_indicator); + localStateView.setImageResource( + file.isFolder() ? + R.drawable.synchronizing_file_indicator : + R.drawable.uploading_file_indicator + ); localStateView.setVisibility(View.VISIBLE); } else if (file.isInConflict()) { // conflict