1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-29 15:51:17 +00:00

Save ignore list reliably when returning from edit folder dialog (fixes #140) (#175)

* Save ignore list reliably when returning from edit folder dialog (fixes #140)

* Do not return on empty ignore list (fixes #140)
This commit is contained in:
Catfriend1 2019-01-01 19:28:57 +01:00 committed by GitHub
parent cf762acb19
commit 936a53ede3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);