Add caldav acct pref to suppress repeating tasks

gtask_related_email
Alex Baker 5 years ago
parent 54318c8f69
commit 95f36a6d47

File diff suppressed because it is too large Load Diff

@ -58,7 +58,7 @@ import org.tasks.notifications.NotificationDao;
CaldavAccount.class,
GoogleTaskAccount.class
},
version = 66)
version = 67)
public abstract class Database extends RoomDatabase {
public static final String NAME = "database";

@ -10,6 +10,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProviders;
@ -95,6 +96,9 @@ public class CaldavAccountSettingsActivity extends ThemedInjectingAppCompatActiv
@BindView(R.id.progress_bar)
ProgressView progressView;
@BindView(R.id.repeat)
SwitchCompat repeat;
private CaldavAccount caldavAccount;
private AddCaldavAccountViewModel addCaldavAccountViewModel;
private UpdateCaldavAccountViewModel updateCaldavAccountViewModel;
@ -121,6 +125,7 @@ public class CaldavAccountSettingsActivity extends ThemedInjectingAppCompatActiv
if (!isEmpty(caldavAccount.getPassword())) {
password.setText(PASSWORD_MASK);
}
repeat.setChecked(caldavAccount.isSuppressRepeatingTasks());
}
}
@ -335,6 +340,7 @@ public class CaldavAccountSettingsActivity extends ThemedInjectingAppCompatActiv
if (passwordChanged()) {
caldavAccount.setPassword(encryption.encrypt(getNewPassword()));
}
caldavAccount.setSuppressRepeatingTasks(repeat.isChecked());
caldavDao.update(caldavAccount);
setResult(RESULT_OK);
@ -376,9 +382,12 @@ public class CaldavAccountSettingsActivity extends ThemedInjectingAppCompatActiv
return !isEmpty(getNewName())
|| !isEmpty(getNewPassword())
|| !isEmpty(getNewURL())
|| !isEmpty(getNewUsername());
|| !isEmpty(getNewUsername())
|| repeat.isChecked();
}
return needsValidation() || !getNewName().equals(caldavAccount.getName());
return needsValidation()
|| !getNewName().equals(caldavAccount.getName())
|| repeat.isChecked() != caldavAccount.isSuppressRepeatingTasks();
}
private boolean needsValidation() {

@ -37,17 +37,16 @@ public class CaldavConverter {
public static void apply(Task local, at.bitfire.ical4android.Task remote) {
Completed completedAt = remote.getCompletedAt();
if (completedAt == null) {
if (remote.getStatus() == Status.VTODO_COMPLETED) {
if (completedAt != null) {
local.setCompletionDate(remote.getCompletedAt().getDate().getTime());
} else if (remote.getStatus() == Status.VTODO_COMPLETED) {
if (!local.isCompleted()) {
local.setCompletionDate(now());
}
} else {
local.setCompletionDate(0L);
}
} else {
local.setCompletionDate(remote.getCompletedAt().getDate().getTime());
}
Long createdAt = remote.getCreatedAt();
if (createdAt != null) {
local.setCreationDate(newDateTime(createdAt).toLocal().getMillis());

@ -4,6 +4,7 @@ import static com.todoroo.astrid.data.Task.NO_UUID;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.core.os.ParcelCompat;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
@ -49,6 +50,9 @@ public class CaldavAccount implements Parcelable {
@ColumnInfo(name = "cda_error")
private transient String error = "";
@ColumnInfo(name = "cda_repeat")
private boolean suppressRepeatingTasks;
public CaldavAccount() {}
@Ignore
@ -60,6 +64,7 @@ public class CaldavAccount implements Parcelable {
username = source.readString();
password = source.readString();
error = source.readString();
suppressRepeatingTasks = ParcelCompat.readBoolean(source);
}
public long getId() {
@ -122,6 +127,14 @@ public class CaldavAccount implements Parcelable {
this.error = error;
}
public boolean isSuppressRepeatingTasks() {
return suppressRepeatingTasks;
}
public void setSuppressRepeatingTasks(boolean suppressRepeatingTasks) {
this.suppressRepeatingTasks = suppressRepeatingTasks;
}
@Override
public String toString() {
return "CaldavAccount{"
@ -145,6 +158,8 @@ public class CaldavAccount implements Parcelable {
+ ", error='"
+ error
+ '\''
+ ", suppressRepeatingTasks="
+ suppressRepeatingTasks
+ '}';
}
@ -162,6 +177,9 @@ public class CaldavAccount implements Parcelable {
if (id != that.id) {
return false;
}
if (suppressRepeatingTasks != that.suppressRepeatingTasks) {
return false;
}
if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) {
return false;
}
@ -189,6 +207,7 @@ public class CaldavAccount implements Parcelable {
result = 31 * result + (username != null ? username.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (error != null ? error.hashCode() : 0);
result = 31 * result + (suppressRepeatingTasks ? 1 : 0);
return result;
}
@ -206,5 +225,6 @@ public class CaldavAccount implements Parcelable {
dest.writeString(username);
dest.writeString(password);
dest.writeString(error);
ParcelCompat.writeBoolean(dest, suppressRepeatingTasks);
}
}

@ -108,6 +108,13 @@ public abstract class CaldavDao {
@Query("SELECT * FROM caldav_accounts WHERE cda_name = :name COLLATE NOCASE LIMIT 1")
public abstract CaldavAccount getAccountByName(String name);
@Query(
"SELECT * from caldav_accounts"
+ " INNER JOIN caldav_tasks ON cd_task = :task"
+ " INNER JOIN caldav_lists ON cd_calendar = cdl_uuid"
+ " WHERE cdl_account = cda_uuid")
public abstract CaldavAccount getAccountForTask(long task);
@Query("SELECT DISTINCT cd_calendar FROM caldav_tasks WHERE cd_deleted = 0 AND cd_task IN (:tasks)")
public abstract List<String> getCalendars(List<Long> tasks);

@ -329,6 +329,15 @@ public class Migrations {
}
};
private static final Migration MIGRATION_66_67 =
new Migration(66, 67) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL(
"ALTER TABLE `caldav_accounts` ADD COLUMN `cda_repeat` INTEGER NOT NULL DEFAULT 0");
}
};
public static final Migration[] MIGRATIONS =
new Migration[] {
MIGRATION_35_36,
@ -352,7 +361,8 @@ public class Migrations {
MIGRATION_62_63,
MIGRATION_63_64,
MIGRATION_64_65,
MIGRATION_65_66
MIGRATION_65_66,
MIGRATION_66_67
};
private static Migration NOOP(int from, int to) {

@ -21,6 +21,8 @@ import com.todoroo.astrid.timers.TimerPlugin;
import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.R;
import org.tasks.data.CaldavAccount;
import org.tasks.data.CaldavDao;
import org.tasks.injection.ForApplication;
import org.tasks.injection.InjectingWorker;
import org.tasks.injection.JobComponent;
@ -50,6 +52,7 @@ public class AfterSaveWork extends InjectingWorker {
@Inject TaskDao taskDao;
@Inject SyncAdapters syncAdapters;
@Inject WorkManager workManager;
@Inject CaldavDao caldavDao;
public AfterSaveWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
@ -104,7 +107,10 @@ public class AfterSaveWork extends InjectingWorker {
if (justCompleted) {
updateCalendarTitle(task);
CaldavAccount account = caldavDao.getAccountForTask(taskId);
if (account == null || !account.isSuppressRepeatingTasks()) {
repeatTaskHelper.handleRepeat(task);
}
if (task.getTimerStart() > 0) {
timerPlugin.stopTimer(task);
}

@ -76,6 +76,13 @@
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/repeat"
style="@style/TagSettingsRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/caldav_account_repeating_tasks"/>
</LinearLayout>
</ScrollView>

@ -547,4 +547,5 @@ File %1$s contained %2$s.\n\n
<string name="name_your_price">Name your price</string>
<string name="monthly">Monthly</string>
<string name="annually">Yearly</string>
<string name="caldav_account_repeating_tasks">Let server schedule recurring tasks</string>
</resources>

Loading…
Cancel
Save