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