Functionality complete, rip wifi?
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="be.mathsaey.stoofnogaan">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/stoofinbrand_icon"
|
||||
|
||||
@@ -51,4 +51,8 @@ public class Task {
|
||||
public boolean isEmpty() {
|
||||
return this.text.length() == 0;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setStatus(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.PriorityQueue;
|
||||
import be.mathsaey.stoofnogaan.BuildConfig;
|
||||
|
||||
public class TaskList implements Iterable<Task> {
|
||||
private final String TASK_FILE = "tasks.txt";
|
||||
private final static String TASK_FILE = "tasks.txt";
|
||||
|
||||
private ArrayList<Task> list;
|
||||
private Task last;
|
||||
@@ -26,8 +26,8 @@ public class TaskList implements Iterable<Task> {
|
||||
last = null;
|
||||
}
|
||||
|
||||
public TaskList(Context c) {
|
||||
this();
|
||||
static public TaskList loadFromFile(Context c) {
|
||||
TaskList res = new TaskList();
|
||||
|
||||
try {
|
||||
FileInputStream input = c.openFileInput(TASK_FILE);
|
||||
@@ -38,15 +38,16 @@ public class TaskList implements Iterable<Task> {
|
||||
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
Task t = Task.fromString(line);
|
||||
list.add(t);
|
||||
last = t;
|
||||
res.add(t);
|
||||
res.last = t;
|
||||
}
|
||||
input.close();
|
||||
return res;
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
// When the file is not found, just don't load.
|
||||
return res;
|
||||
} catch (IOException e) {
|
||||
Log.d(BuildConfig.APPLICATION_ID, Log.getStackTraceString(e));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +77,12 @@ public class TaskList implements Iterable<Task> {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (Task t: list) {
|
||||
t.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Task t) {
|
||||
list.add(t);
|
||||
last = t;
|
||||
|
||||
@@ -13,7 +13,6 @@ import be.mathsaey.stoofnogaan.data.Task;
|
||||
import be.mathsaey.stoofnogaan.data.TaskList;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
// View which contains all the tasks
|
||||
private LinearLayout taskView;
|
||||
private TaskList list;
|
||||
|
||||
@@ -45,7 +44,7 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
public void loadTasks() {
|
||||
list = new TaskList(this);
|
||||
list = TaskList.loadFromFile(this);
|
||||
for (Task t: list) {
|
||||
TaskView v = new TaskView(this, t);
|
||||
taskView.addView(v);
|
||||
@@ -62,6 +61,15 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
public void onResetTaskButtonClick(View _button) {
|
||||
list.reset();
|
||||
|
||||
for (int i = 0; i < taskView.getChildCount(); i++) {
|
||||
TaskView v = (TaskView) taskView.getChildAt(i);
|
||||
v.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteTask(TaskView v) {
|
||||
taskView.removeView(v);
|
||||
list.remove(v.getTask());
|
||||
|
||||
@@ -11,7 +11,7 @@ import android.widget.Toast;
|
||||
import be.mathsaey.stoofnogaan.R;
|
||||
import be.mathsaey.stoofnogaan.data.Task;
|
||||
|
||||
class TaskView extends LinearLayout {
|
||||
public class TaskView extends LinearLayout {
|
||||
private Task task;
|
||||
|
||||
private MainActivity parent;
|
||||
@@ -35,11 +35,16 @@ class TaskView extends LinearLayout {
|
||||
addTextListeners();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
public void updateTask() {
|
||||
task.setText(textView.getText().toString());
|
||||
task.setStatus(checkBox.isChecked());
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
checkBox.setChecked(task.getStatus());
|
||||
textView.setText(task.getText());
|
||||
}
|
||||
|
||||
public Task getTask() {
|
||||
return this.task;
|
||||
}
|
||||
@@ -58,7 +63,7 @@ class TaskView extends LinearLayout {
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
TaskView.this.update();
|
||||
TaskView.this.updateTask();
|
||||
if (task.isEmpty()) {
|
||||
parent.deleteTask(TaskView.this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user