mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-30 00:01:19 +00:00
* 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:
parent
cf762acb19
commit
936a53ede3
1 changed files with 25 additions and 21 deletions
|
@ -121,6 +121,7 @@ public class FolderActivity extends SyncthingActivity
|
||||||
|
|
||||||
private boolean mIsCreateMode;
|
private boolean mIsCreateMode;
|
||||||
private boolean mFolderNeedsToUpdate = false;
|
private boolean mFolderNeedsToUpdate = false;
|
||||||
|
private boolean mIgnoreListNeedsToUpdate = false;
|
||||||
|
|
||||||
private Dialog mDeleteDialog;
|
private Dialog mDeleteDialog;
|
||||||
private Dialog mDiscardDialog;
|
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 =
|
private final CompoundButton.OnCheckedChangeListener mCheckedListener =
|
||||||
new CompoundButton.OnCheckedChangeListener() {
|
new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -352,18 +361,12 @@ public class FolderActivity extends SyncthingActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
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();
|
super.onPause();
|
||||||
|
|
||||||
// We don't want to update every time a TextView's character changes,
|
// 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.
|
// so we hold off until the view stops being visible to the user.
|
||||||
if (mFolderNeedsToUpdate) {
|
if (mFolderNeedsToUpdate) {
|
||||||
Log.v(TAG, "onPause: mFolderNeedsToUpdate == true");
|
Log.v(TAG, "onPause: mFolderNeedsToUpdate=true, mIgnoreListNeedsToUpdate=" + Boolean.toString(mIgnoreListNeedsToUpdate));
|
||||||
updateFolder();
|
updateFolder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,7 +381,7 @@ public class FolderActivity extends SyncthingActivity
|
||||||
}
|
}
|
||||||
mLabelView.removeTextChangedListener(mTextWatcher);
|
mLabelView.removeTextChangedListener(mTextWatcher);
|
||||||
mIdView.removeTextChangedListener(mTextWatcher);
|
mIdView.removeTextChangedListener(mTextWatcher);
|
||||||
mEditIgnoreListContent.removeTextChangedListener(mTextWatcher);
|
mEditIgnoreListContent.removeTextChangedListener(mIgnoreListContentTextWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -441,15 +444,13 @@ public class FolderActivity extends SyncthingActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onReceiveFolderIgnoreList(FolderIgnoreList folderIgnoreList) {
|
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.setMaxLines(Integer.MAX_VALUE);
|
||||||
mEditIgnoreListContent.removeTextChangedListener(mTextWatcher);
|
mEditIgnoreListContent.removeTextChangedListener(mIgnoreListContentTextWatcher);
|
||||||
mEditIgnoreListContent.setText(ignoreList);
|
if (folderIgnoreList.ignore != null) {
|
||||||
mEditIgnoreListContent.addTextChangedListener(mTextWatcher);
|
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
|
// 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.
|
* Sends the updated folder info if in edit mode.
|
||||||
* Preconditions: mFolderNeedsToUpdate == true
|
* Preconditions:
|
||||||
|
* mFolderNeedsToUpdate == true
|
||||||
|
* mIgnoreListNeedsToUpdate == true (Optional)
|
||||||
*/
|
*/
|
||||||
private void updateFolder() {
|
private void updateFolder() {
|
||||||
if (mIsCreateMode) {
|
if (mIsCreateMode) {
|
||||||
|
@ -759,10 +762,11 @@ public class FolderActivity extends SyncthingActivity
|
||||||
|
|
||||||
// Update folder via restApi and send the config to REST endpoint.
|
// Update folder via restApi and send the config to REST endpoint.
|
||||||
RestApi restApi = getApi();
|
RestApi restApi = getApi();
|
||||||
|
if (mIgnoreListNeedsToUpdate) {
|
||||||
// Update ignore list.
|
// Update ignore list.
|
||||||
String[] ignore = mEditIgnoreListContent.getText().toString().split("\n");
|
String[] ignore = mEditIgnoreListContent.getText().toString().split("\n");
|
||||||
mConfig.postFolderIgnoreList(restApi, mFolder, ignore);
|
mConfig.postFolderIgnoreList(restApi, mFolder, ignore);
|
||||||
|
}
|
||||||
|
|
||||||
// Update folder using RestApi or ConfigXml.
|
// Update folder using RestApi or ConfigXml.
|
||||||
mConfig.updateFolder(restApi, mFolder);
|
mConfig.updateFolder(restApi, mFolder);
|
||||||
|
|
Loading…
Reference in a new issue