diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java index 030f1479..8fe29edb 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java @@ -121,6 +121,7 @@ public class FolderActivity extends SyncthingActivity private boolean mIsCreateMode; private boolean mFolderNeedsToUpdate = false; + private boolean mIgnoreListNeedsToUpdate = false; private Dialog mDeleteDialog; private Dialog mDiscardDialog; @@ -138,6 +139,14 @@ public class FolderActivity extends SyncthingActivity } }; + private final TextWatcher mIgnoreListContentTextWatcher = new TextWatcherAdapter() { + @Override + public void afterTextChanged(Editable s) { + mIgnoreListNeedsToUpdate = true; + mFolderNeedsToUpdate = true; + } + }; + private final CompoundButton.OnCheckedChangeListener mCheckedListener = new CompoundButton.OnCheckedChangeListener() { @Override @@ -352,18 +361,12 @@ public class FolderActivity extends SyncthingActivity @Override public void onPause() { - try { - // This should trigger {@link #mTextWatcher} if the element still has the focus. - mEditIgnoreListContent.clearFocus(); - } catch (Exception e) { - Log.e(TAG, "onPause: mEditIgnoreListContent", e); - } super.onPause(); // We don't want to update every time a TextView's character changes, // so we hold off until the view stops being visible to the user. if (mFolderNeedsToUpdate) { - Log.v(TAG, "onPause: mFolderNeedsToUpdate == true"); + Log.v(TAG, "onPause: mFolderNeedsToUpdate=true, mIgnoreListNeedsToUpdate=" + Boolean.toString(mIgnoreListNeedsToUpdate)); updateFolder(); } } @@ -378,7 +381,7 @@ public class FolderActivity extends SyncthingActivity } mLabelView.removeTextChangedListener(mTextWatcher); mIdView.removeTextChangedListener(mTextWatcher); - mEditIgnoreListContent.removeTextChangedListener(mTextWatcher); + mEditIgnoreListContent.removeTextChangedListener(mIgnoreListContentTextWatcher); } @Override @@ -441,15 +444,13 @@ public class FolderActivity extends SyncthingActivity } private void onReceiveFolderIgnoreList(FolderIgnoreList folderIgnoreList) { - if (folderIgnoreList.ignore == null) { - Log.w(TAG, "onReceiveFolderIgnoreList: folderIgnoreList == null."); - return; - } - String ignoreList = TextUtils.join("\n", folderIgnoreList.ignore); mEditIgnoreListContent.setMaxLines(Integer.MAX_VALUE); - mEditIgnoreListContent.removeTextChangedListener(mTextWatcher); - mEditIgnoreListContent.setText(ignoreList); - mEditIgnoreListContent.addTextChangedListener(mTextWatcher); + mEditIgnoreListContent.removeTextChangedListener(mIgnoreListContentTextWatcher); + if (folderIgnoreList.ignore != null) { + String ignoreList = TextUtils.join("\n", folderIgnoreList.ignore); + mEditIgnoreListContent.setText(ignoreList); + } + mEditIgnoreListContent.addTextChangedListener(mIgnoreListContentTextWatcher); } // If the FolderActivity gets recreated after the VersioningDialogActivity is closed, then the result from the VersioningDialogActivity will be received before @@ -736,7 +737,9 @@ public class FolderActivity extends SyncthingActivity /** * Sends the updated folder info if in edit mode. - * Preconditions: mFolderNeedsToUpdate == true + * Preconditions: + * mFolderNeedsToUpdate == true + * mIgnoreListNeedsToUpdate == true (Optional) */ private void updateFolder() { if (mIsCreateMode) { @@ -759,10 +762,11 @@ public class FolderActivity extends SyncthingActivity // Update folder via restApi and send the config to REST endpoint. RestApi restApi = getApi(); - - // Update ignore list. - String[] ignore = mEditIgnoreListContent.getText().toString().split("\n"); - mConfig.postFolderIgnoreList(restApi, mFolder, ignore); + if (mIgnoreListNeedsToUpdate) { + // Update ignore list. + String[] ignore = mEditIgnoreListContent.getText().toString().split("\n"); + mConfig.postFolderIgnoreList(restApi, mFolder, ignore); + } // Update folder using RestApi or ConfigXml. mConfig.updateFolder(restApi, mFolder);