Add caldav acct pref to suppress repeating tasks

gtask_related_email
Alex Baker 6 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, CaldavAccount.class,
GoogleTaskAccount.class GoogleTaskAccount.class
}, },
version = 66) version = 67)
public abstract class Database extends RoomDatabase { public abstract class Database extends RoomDatabase {
public static final String NAME = "database"; public static final String NAME = "database";

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

@ -37,17 +37,16 @@ public class CaldavConverter {
public static void apply(Task local, at.bitfire.ical4android.Task remote) { public static void apply(Task local, at.bitfire.ical4android.Task remote) {
Completed completedAt = remote.getCompletedAt(); Completed completedAt = remote.getCompletedAt();
if (completedAt == null) { if (completedAt != null) {
if (remote.getStatus() == Status.VTODO_COMPLETED) { local.setCompletionDate(remote.getCompletedAt().getDate().getTime());
} else if (remote.getStatus() == Status.VTODO_COMPLETED) {
if (!local.isCompleted()) { if (!local.isCompleted()) {
local.setCompletionDate(now()); local.setCompletionDate(now());
} }
} else { } else {
local.setCompletionDate(0L); local.setCompletionDate(0L);
} }
} else {
local.setCompletionDate(remote.getCompletedAt().getDate().getTime());
}
Long createdAt = remote.getCreatedAt(); Long createdAt = remote.getCreatedAt();
if (createdAt != null) { if (createdAt != null) {
local.setCreationDate(newDateTime(createdAt).toLocal().getMillis()); 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.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.core.os.ParcelCompat;
import androidx.room.ColumnInfo; import androidx.room.ColumnInfo;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.Ignore; import androidx.room.Ignore;
@ -49,6 +50,9 @@ public class CaldavAccount implements Parcelable {
@ColumnInfo(name = "cda_error") @ColumnInfo(name = "cda_error")
private transient String error = ""; private transient String error = "";
@ColumnInfo(name = "cda_repeat")
private boolean suppressRepeatingTasks;
public CaldavAccount() {} public CaldavAccount() {}
@Ignore @Ignore
@ -60,6 +64,7 @@ public class CaldavAccount implements Parcelable {
username = source.readString(); username = source.readString();
password = source.readString(); password = source.readString();
error = source.readString(); error = source.readString();
suppressRepeatingTasks = ParcelCompat.readBoolean(source);
} }
public long getId() { public long getId() {
@ -122,6 +127,14 @@ public class CaldavAccount implements Parcelable {
this.error = error; this.error = error;
} }
public boolean isSuppressRepeatingTasks() {
return suppressRepeatingTasks;
}
public void setSuppressRepeatingTasks(boolean suppressRepeatingTasks) {
this.suppressRepeatingTasks = suppressRepeatingTasks;
}
@Override @Override
public String toString() { public String toString() {
return "CaldavAccount{" return "CaldavAccount{"
@ -145,6 +158,8 @@ public class CaldavAccount implements Parcelable {
+ ", error='" + ", error='"
+ error + error
+ '\'' + '\''
+ ", suppressRepeatingTasks="
+ suppressRepeatingTasks
+ '}'; + '}';
} }
@ -162,6 +177,9 @@ public class CaldavAccount implements Parcelable {
if (id != that.id) { if (id != that.id) {
return false; return false;
} }
if (suppressRepeatingTasks != that.suppressRepeatingTasks) {
return false;
}
if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) { if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) {
return false; return false;
} }
@ -189,6 +207,7 @@ public class CaldavAccount implements Parcelable {
result = 31 * result + (username != null ? username.hashCode() : 0); result = 31 * result + (username != null ? username.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0); result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (error != null ? error.hashCode() : 0); result = 31 * result + (error != null ? error.hashCode() : 0);
result = 31 * result + (suppressRepeatingTasks ? 1 : 0);
return result; return result;
} }
@ -206,5 +225,6 @@ public class CaldavAccount implements Parcelable {
dest.writeString(username); dest.writeString(username);
dest.writeString(password); dest.writeString(password);
dest.writeString(error); 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") @Query("SELECT * FROM caldav_accounts WHERE cda_name = :name COLLATE NOCASE LIMIT 1")
public abstract CaldavAccount getAccountByName(String name); 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)") @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); 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 = public static final Migration[] MIGRATIONS =
new Migration[] { new Migration[] {
MIGRATION_35_36, MIGRATION_35_36,
@ -352,7 +361,8 @@ public class Migrations {
MIGRATION_62_63, MIGRATION_62_63,
MIGRATION_63_64, MIGRATION_63_64,
MIGRATION_64_65, MIGRATION_64_65,
MIGRATION_65_66 MIGRATION_65_66,
MIGRATION_66_67
}; };
private static Migration NOOP(int from, int to) { private static Migration NOOP(int from, int to) {

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

@ -76,6 +76,13 @@
</com.google.android.material.textfield.TextInputLayout> </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> </LinearLayout>
</ScrollView> </ScrollView>

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

Loading…
Cancel
Save