Apply to all: enable/disable sync

pull/199/head
M66B 4 years ago
parent e43cbb46da
commit 3452cc5089

@ -325,10 +325,9 @@ public interface DaoFolder {
@Query("UPDATE folder" +
" SET sync_days = :sync_days, keep_days = :keep_days" +
" WHERE account = :account" +
" AND type = '" + EntityFolder.USER + "'" +
" AND (NOT (sync_days IS :sync_days) OR NOT (keep_days IS :keep_days))")
int setFolderProperties(long account, int sync_days, int keep_days);
" WHERE id = :id" +
" AND NOT (sync_days IS :sync_days AND keep_days IS :keep_days)")
int setFolderProperties(long id, int sync_days, int keep_days);
@Query("UPDATE folder SET keywords = :keywords WHERE id = :id AND NOT (keywords IS :keywords)")
int setFolderKeywords(long id, String keywords);

@ -41,6 +41,7 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -1012,6 +1013,7 @@ public class FragmentFolders extends FragmentBase {
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_folder_all, null);
final RadioGroup rgSynchronize = view.findViewById(R.id.rgSynchronize);
final EditText etSyncDays = view.findViewById(R.id.etSyncDays);
final EditText etKeepDays = view.findViewById(R.id.etKeepDays);
final CheckBox cbKeepAll = view.findViewById(R.id.cbKeepAll);
@ -1031,6 +1033,11 @@ public class FragmentFolders extends FragmentBase {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = getArguments();
int optionId = rgSynchronize.getCheckedRadioButtonId();
if (optionId == R.id.rbEnable)
args.putBoolean("enable", true);
else if (optionId == R.id.rbDisable)
args.putBoolean("enable", false);
args.putString("sync", etSyncDays.getText().toString());
args.putString("keep", cbKeepAll.isChecked()
? Integer.toString(Integer.MAX_VALUE)
@ -1042,6 +1049,9 @@ public class FragmentFolders extends FragmentBase {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long account = args.getLong("account");
Boolean enable = null;
if (args.containsKey("enable"))
enable = args.getBoolean("enable");
String sync = args.getString("sync");
String keep = args.getString("keep");
boolean system = args.getBoolean("system");
@ -1056,19 +1066,29 @@ public class FragmentFolders extends FragmentBase {
try {
db.beginTransaction();
db.folder().setFolderProperties(
account,
Integer.parseInt(sync),
Integer.parseInt(keep));
List<EntityFolder> folders = db.folder().getFolders(account, false, true);
if (folders != null)
for (EntityFolder folder : folders)
if (folder.synchronize && !folder.poll)
if (EntityFolder.USER.equals(folder.type)
? user
: system && !EntityFolder.INBOX.equals(folder.type))
db.folder().setFolderPoll(folder.id, true);
if (folders == null)
return null;
for (EntityFolder folder : folders) {
if (EntityFolder.USER.equals(folder.type)) {
if (enable != null) {
folder.synchronize = enable;
db.folder().setFolderSynchronize(folder.id, folder.synchronize);
}
db.folder().setFolderProperties(
folder.id,
Integer.parseInt(sync),
Integer.parseInt(keep));
}
if (folder.synchronize && !folder.poll)
if (EntityFolder.USER.equals(folder.type)
? user
: system && !EntityFolder.INBOX.equals(folder.type))
db.folder().setFolderPoll(folder.id, true);
}
db.setTransactionSuccessful();
} finally {

@ -26,20 +26,67 @@
android:layout_marginTop="12dp"
android:text="@string/title_folder_user_only"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic|bold"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSyncDays"
android:id="@+id/tvSynchronize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_sync_days"
android:text="@string/tile_synchronize"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUser" />
<RadioGroup
android:id="@+id/rgSynchronize"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSynchronize">
<RadioButton
android:id="@+id/rbCurrent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:padding="6dp"
android:text="@string/title_keep_current"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
<RadioButton
android:id="@+id/rbEnable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/title_enable"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
<RadioButton
android:id="@+id/rbDisable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/title_disable"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</RadioGroup>
<eu.faircode.email.FixedTextView
android:id="@+id/tvSyncDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_sync_days"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rgSynchronize" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etSyncDays"
android:layout_width="0dp"

@ -1506,6 +1506,8 @@
<string name="title_fix">Fix</string>
<string name="title_enable">Enable</string>
<string name="title_enabled">Enabled</string>
<string name="title_disable">Disable</string>
<string name="title_keep_current">Keep current</string>
<string name="title_executing">Executing</string>
<string name="title_completed">Completed</string>
<string name="title_default_changed">Default changed</string>

Loading…
Cancel
Save