Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated so that TaskBagImpl.Preferences are read dynamically

  • Loading branch information...
commit 87ac0a046b14897c472919e8b064bb81c66d0cfb 1 parent b2eb5b5
@timbarlotta timbarlotta authored tormodh committed
View
13 src/com/todotxt/todotxttouch/TodoTxtTouch.java
@@ -78,7 +78,6 @@
import com.todotxt.todotxttouch.task.Sort;
import com.todotxt.todotxttouch.task.Task;
import com.todotxt.todotxttouch.task.TaskBag;
-import com.todotxt.todotxttouch.task.TaskBagImpl;
import com.todotxt.todotxttouch.util.Strings;
import com.todotxt.todotxttouch.util.Util;
import com.todotxt.todotxttouch.util.Util.OnMultiChoiceDialogListener;
@@ -219,18 +218,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
Log.i(TAG, "New access token secret. Syncing!");
populateFromExternal();
}
- // TODO update taskBag preferences values here
- TaskBagImpl.Preferences taskBagPreferences = new TaskBagImpl.Preferences.Builder(
- sharedPreferences.getString("todotxtpath", "/todo"))
- .useWindowsLineBreaks(
- sharedPreferences.getBoolean("linebreakspref", false))
- .shouldPrependDate(
- sharedPreferences.getBoolean("todotxtprependdate",
- false))
- .workOffline(sharedPreferences.getBoolean("workoffline", false))
- .build();
- this.taskBag.updatePreferences(taskBagPreferences);
-
}
@Override
View
4 src/com/todotxt/todotxttouch/task/LocalFileTaskRepository.java
@@ -37,7 +37,7 @@
/**
* A task repository for interacting with the local file system
- *
+ *
* @author Tim Barlotta
*/
class LocalFileTaskRepository implements LocalTaskRepository {
@@ -88,6 +88,6 @@ public void purge() {
@Override
public void store(ArrayList<Task> tasks) {
TaskIo.writeToFile(tasks, TODO_TXT_FILE,
- preferences.useWindowsLineBreaks);
+ preferences.isUseWindowsLineBreaksEnabled());
}
}
View
4 src/com/todotxt/todotxttouch/task/TaskBag.java
@@ -32,7 +32,7 @@
/**
* Interface for interacting with the tasks in aggregate
- *
+ *
* @author Tim Barlotta
*/
public interface TaskBag {
@@ -44,8 +44,6 @@
void delete(Task task);
- void updatePreferences(TaskBagImpl.Preferences preferences);
-
List<Task> getTasks();
List<Task> getTasks(Filter<Task> filter, Comparator<Task> comparator);
View
14 src/com/todotxt/todotxttouch/task/TaskBagFactory.java
@@ -32,20 +32,14 @@
/**
* A factory for creating TaskBags
- *
+ *
* @author Tim Barlotta
*/
public class TaskBagFactory {
public static TaskBag getTaskBag(TodoApplication application,
- SharedPreferences preferences, String defaultTodoTxtPath) {
- TaskBagImpl.Preferences taskBagPreferences = new TaskBagImpl.Preferences.Builder(
- preferences.getString("todotxtpath", defaultTodoTxtPath))
- .useWindowsLineBreaks(
- preferences.getBoolean("linebreakspref", false))
- .shouldPrependDate(
- preferences.getBoolean("todotxtprependdate", false))
- .workOffline(preferences.getBoolean("workoffline", false))
- .build();
+ SharedPreferences sharedPreferences, String defaultTodoTxtPath) {
+ TaskBagImpl.Preferences taskBagPreferences = new TaskBagImpl.Preferences(
+ sharedPreferences, defaultTodoTxtPath);
LocalFileTaskRepository localFileTaskRepository = new LocalFileTaskRepository(
taskBagPreferences);
View
85 src/com/todotxt/todotxttouch/task/TaskBagImpl.java
@@ -24,6 +24,7 @@
*/
package com.todotxt.todotxttouch.task;
+import android.content.SharedPreferences;
import android.util.Log;
import java.util.ArrayList;
@@ -38,10 +39,10 @@
/**
* Implementation of the TaskBag interface
- *
+ *
* @author Tim Barlotta
*/
-public class TaskBagImpl implements TaskBag {
+class TaskBagImpl implements TaskBag {
private static final String TAG = TaskBagImpl.class.getSimpleName();
private Preferences preferences;
private final LocalTaskRepository localRepository;
@@ -103,7 +104,7 @@ public void addAsTask(String input) {
try {
reload();
Task task = new Task(tasks.size(), input,
- (preferences.shouldPrependDate ? new Date() : null));
+ (preferences.isPrependDateEnabled() ? new Date() : null));
tasks.add(task);
localRepository.store(tasks);
pushToRemote();
@@ -167,7 +168,7 @@ public void disconnectFromRemote() {
@Override
public void pushToRemote() {
- if (!this.preferences.workOffline) {
+ if (!this.preferences.isWorkOfflineEnabled()) {
ArrayList<Task> localTasks = localRepository.load();
remoteTaskRepository.store(localTasks);
}
@@ -175,7 +176,7 @@ public void pushToRemote() {
@Override
public void pullFromRemote() {
- if (!this.preferences.workOffline) {
+ if (!this.preferences.isWorkOfflineEnabled()) {
this.tasks = remoteTaskRepository.load();
localRepository.store(tasks);
}
@@ -228,68 +229,28 @@ private static Task find(List<Task> tasks, Task task) {
}
public static class Preferences {
- // TODO need to allow for changing this
- final String todoFileDirectory;
- final boolean shouldPrependDate;
- final boolean useWindowsLineBreaks;
- final boolean workOffline;
+ private final String defaultTodoFileDirectory;
+ private final SharedPreferences sharedPreferences;
- private Preferences(Builder builder) {
- this.todoFileDirectory = builder.todoFileDirectory;
- this.shouldPrependDate = builder.shouldPrependDate;
- this.useWindowsLineBreaks = builder.useWindowsLineBreaks;
- this.workOffline = builder.workOffline;
+ public Preferences(SharedPreferences sharedPreferences, String defaultTodoFileDirectory) {
+ this.sharedPreferences = sharedPreferences;
+ this.defaultTodoFileDirectory = defaultTodoFileDirectory;
}
- public static class Builder {
- private String todoFileDirectory;
- private boolean shouldPrependDate = false;
- private boolean useWindowsLineBreaks = false;
- private boolean workOffline = false;
+ public String getTodoTextPath() {
+ return sharedPreferences.getString("todotxtpath", defaultTodoFileDirectory);
+ }
- public Builder(String todoFileDirectory) {
- this.todoFileDirectory = todoFileDirectory;
- }
+ public boolean isUseWindowsLineBreaksEnabled() {
+ return sharedPreferences.getBoolean("linebreakspref", false);
+ }
- /**
- * Sets the shouldPrependDate value in the builder
- *
- * @param shouldPrependDate
- * the value to set
- * @return this builder
- */
- public Builder shouldPrependDate(boolean shouldPrependDate) {
- this.shouldPrependDate = shouldPrependDate;
- return this;
- }
-
- /**
- * Sets the useWindowsLineBreaks value in the builder
- *
- * @param useWindowsLineBreaks
- * the value to set
- * @return this builder
- */
- public Builder useWindowsLineBreaks(boolean useWindowsLineBreaks) {
- this.useWindowsLineBreaks = useWindowsLineBreaks;
- return this;
- }
+ public boolean isPrependDateEnabled() {
+ return sharedPreferences.getBoolean("todotxtprependdate", false);
+ }
- /**
- * Sets the workOffline value in the builder
- *
- * @param workOffline
- * the value to set
- * @return this builder
- */
- public Builder workOffline(boolean workOffline) {
- this.workOffline = workOffline;
- return this;
- }
-
- public Preferences build() {
- return new Preferences(this);
- }
- }
+ public boolean isWorkOfflineEnabled() {
+ return sharedPreferences.getBoolean("workoffline", false);
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.