diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 912de46..cf84b5d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ android:roundIcon="@mipmap/stoofinbrand_icon" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/assets/fonts/Oswald-SemiBold.ttf b/app/src/main/assets/fonts/Oswald-SemiBold.ttf new file mode 100644 index 0000000..80c4885 Binary files /dev/null and b/app/src/main/assets/fonts/Oswald-SemiBold.ttf differ diff --git a/app/src/main/java/be/mathsaey/stoofnogaan/MainActivity.java b/app/src/main/java/be/mathsaey/stoofnogaan/MainActivity.java deleted file mode 100644 index 9e91521..0000000 --- a/app/src/main/java/be/mathsaey/stoofnogaan/MainActivity.java +++ /dev/null @@ -1,111 +0,0 @@ -package be.mathsaey.stoofnogaan; - -import android.app.Activity; -import android.content.Context; -import android.content.res.AssetManager; -import android.os.Bundle; -import android.util.Log; -import android.view.Menu; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; - -public class MainActivity extends Activity { - - // View which contains all the tasks - private LinearLayout taskView; - private TaskView lastChild; - - private final String TASKS_FILE = "tasks.txt"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - taskView = findViewById(R.id.tasks); - loadFromFile(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - writeToFile(); - taskView.removeAllViews(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } - - public void onNewTaskButtonClick(View v) { - if (lastChild == null || !lastChild.isEmpty()) { - TaskView task = new TaskView(this); - taskView.addView(task); - lastChild = task; - } - } - - public void deleteTask(TaskView v) { - taskView.removeView(v); - - if (taskView.getChildCount() == 0){ - lastChild = null; - } - } - - private void writeToFile() { - try { - FileOutputStream output = openFileOutput(TASKS_FILE, Context.MODE_PRIVATE); - - for (int i = 0; i < taskView.getChildCount(); i++) { - TaskView v = (TaskView) taskView.getChildAt(i); - if (!v.isEmpty()) { - String s = v.toString() + "\n"; - output.write(s.getBytes()); - } - } - - output.close(); - } - catch (FileNotFoundException e) { - Log.e(BuildConfig.APPLICATION_ID, "Could not find file for writing, that's weird..."); - } - catch (IOException e) { - Log.e(BuildConfig.APPLICATION_ID, "Error when trying to write, deleting"); - - } - } - - private void loadFromFile() { - try { - FileInputStream input = openFileInput(TASKS_FILE); - - InputStreamReader streamReader = new InputStreamReader(input); - BufferedReader bufferedReader = new BufferedReader(streamReader); - String line; - - while ((line = bufferedReader.readLine()) != null) { - TaskView task = new TaskView(this, line); - taskView.addView(task); - lastChild = task; - } - input.close(); - } - catch (IOException e) {} - catch (Exception e) { - Log.w(BuildConfig.APPLICATION_ID, Log.getStackTraceString(e)); - } - - } -} \ No newline at end of file diff --git a/app/src/main/java/be/mathsaey/stoofnogaan/TaskView.java b/app/src/main/java/be/mathsaey/stoofnogaan/TaskView.java deleted file mode 100644 index 1489875..0000000 --- a/app/src/main/java/be/mathsaey/stoofnogaan/TaskView.java +++ /dev/null @@ -1,77 +0,0 @@ -package be.mathsaey.stoofnogaan; - -import android.util.Log; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.View; -import android.view.inputmethod.EditorInfo; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; - -class TaskView extends LinearLayout { - private MainActivity parent; - - protected CheckBox checkBox; - protected EditText textView; - - public TaskView(MainActivity p) { - super(p); - - LayoutInflater.from(p).inflate(R.layout.task, this); - - parent = p; - checkBox = findViewById(R.id.checkBox); - textView = findViewById(R.id.textView); - - addTextListeners(); - } - - public TaskView(MainActivity p, String s) { - this(p); - - if (!s.isEmpty()) { - Log.d(BuildConfig.APPLICATION_ID, s); - String[] split = s.split("\\t"); - checkBox.setChecked(split[0].equalsIgnoreCase("true")); - textView.setText(split[1]); - } - } - - public boolean isEmpty() { - return textView.getText().length() == 0; - } - - public String toString() { - return String.format("%s\t%s", checkBox.isChecked(), textView.getText()); - } - - // Android is horrible, this code tries to figure out when the user finished editing. - // When this is the case, check if the text field is empty, delete the taskview if this is - // the case. - private void addTextListeners() { - // When done is clicked... - // Or not because that is when things start to go boom - textView.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { - if (i == EditorInfo.IME_ACTION_DONE && TaskView.this.isEmpty()) { - parent.deleteTask(TaskView.this); - return true; - } - return false; - } - }); - - // Or when we lose focus - textView.setOnFocusChangeListener(new OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean b) { - if (!b && TaskView.this.isEmpty()) { - parent.deleteTask(TaskView.this); - } - } - }); - } -} diff --git a/app/src/main/java/be/mathsaey/stoofnogaan/data/Task.java b/app/src/main/java/be/mathsaey/stoofnogaan/data/Task.java new file mode 100644 index 0000000..ee46ebe --- /dev/null +++ b/app/src/main/java/be/mathsaey/stoofnogaan/data/Task.java @@ -0,0 +1,54 @@ +package be.mathsaey.stoofnogaan.data; + +public class Task { + private String text; + private boolean done; + + public Task() { + text = ""; + done = false; + } + + public Task(String s) { + this(); + text = s; + } + + public Task(String s, boolean b) { + this(s); + done = b; + } + + static public Task fromString(String s) { + Task res = new Task(); + + if (!s.isEmpty()) { + String[] split = s.split("\\t"); + res.done = Boolean.parseBoolean(split[0]); + res.text = split.length > 1 ? split[1] : ""; + } + return res; + } + + public String toString() { + return String.format("%s\t%s\n", done, text); + } + + public boolean getStatus() { + return this.done; + } + public void setStatus(boolean b) { + this.done = b; + } + + public String getText() { + return this.text; + } + public void setText(String s) { + this.text = s; + } + + public boolean isEmpty() { + return this.text.length() == 0; + } +} diff --git a/app/src/main/java/be/mathsaey/stoofnogaan/data/TaskList.java b/app/src/main/java/be/mathsaey/stoofnogaan/data/TaskList.java new file mode 100644 index 0000000..e218eba --- /dev/null +++ b/app/src/main/java/be/mathsaey/stoofnogaan/data/TaskList.java @@ -0,0 +1,100 @@ +package be.mathsaey.stoofnogaan.data; + +import android.content.Context; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.PriorityQueue; + +import be.mathsaey.stoofnogaan.BuildConfig; + +public class TaskList implements Iterable { + private final String TASK_FILE = "tasks.txt"; + + private ArrayList list; + private Task last; + + public TaskList() { + list = new ArrayList(); + last = null; + } + + public TaskList(Context c) { + this(); + + try { + FileInputStream input = c.openFileInput(TASK_FILE); + InputStreamReader inputReader = new InputStreamReader(input); + BufferedReader bufferedReader = new BufferedReader(inputReader); + + String line; + + while ((line = bufferedReader.readLine()) != null) { + Task t = Task.fromString(line); + list.add(t); + last = t; + } + input.close(); + + } catch (FileNotFoundException e) { + // When the file is not found, just don't load. + } catch (IOException e) { + Log.d(BuildConfig.APPLICATION_ID, Log.getStackTraceString(e)); + } + } + + public void writeToFile(Context c) { + try { + FileOutputStream output = c.openFileOutput(TASK_FILE, Context.MODE_PRIVATE); + + for (Task t: list) { + String s = t.toString(); + output.write(s.getBytes()); + } + output.close(); + + } catch (FileNotFoundException e) { + Log.e(BuildConfig.APPLICATION_ID, "Could not find file for writing, that's weird..."); + } catch (IOException e) { + Log.e(BuildConfig.APPLICATION_ID, "Error when trying to write, this make me sad"); + } + } + + public boolean isFinished() { + for (Task t: list) { + if (!t.getStatus()) { + return false; + } + } + return true; + } + + public void add(Task t) { + list.add(t); + last = t; + } + + public void remove(Task t) { + list.remove(t); + + if (list.size() == 0) { + last = null; + } + } + + public boolean canAddNew() { + return (last == null) || (!last.isEmpty()); + } + + @Override + public Iterator iterator() { + return list.iterator(); + } +} diff --git a/app/src/main/java/be/mathsaey/stoofnogaan/ui/MainActivity.java b/app/src/main/java/be/mathsaey/stoofnogaan/ui/MainActivity.java new file mode 100644 index 0000000..a3f5a88 --- /dev/null +++ b/app/src/main/java/be/mathsaey/stoofnogaan/ui/MainActivity.java @@ -0,0 +1,69 @@ +package be.mathsaey.stoofnogaan.ui; + +import android.app.Activity; +import android.graphics.Typeface; +import android.os.Bundle; +import android.view.Menu; +import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; + +import be.mathsaey.stoofnogaan.R; +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; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + taskView = findViewById(R.id.tasks); + loadTasks(); + + Button button = (Button) findViewById(R.id.addButton); + Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/Oswald-SemiBold.ttf"); + button.setTypeface(custom_font); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + list.writeToFile(this); + taskView.removeAllViews(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + public void loadTasks() { + list = new TaskList(this); + for (Task t: list) { + TaskView v = new TaskView(this, t); + taskView.addView(v); + } + } + + public void onNewTaskButtonClick(View _button) { + if (list.canAddNew()) { + Task t = new Task(); + TaskView v = new TaskView(this, t); + + list.add(t); + taskView.addView(v); + } + } + + public void deleteTask(TaskView v) { + taskView.removeView(v); + list.remove(v.getTask()); + } +} \ No newline at end of file diff --git a/app/src/main/java/be/mathsaey/stoofnogaan/ui/TaskView.java b/app/src/main/java/be/mathsaey/stoofnogaan/ui/TaskView.java new file mode 100644 index 0000000..1354117 --- /dev/null +++ b/app/src/main/java/be/mathsaey/stoofnogaan/ui/TaskView.java @@ -0,0 +1,68 @@ +package be.mathsaey.stoofnogaan.ui; + +import android.text.Editable; +import android.text.TextWatcher; +import android.view.LayoutInflater; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Toast; + +import be.mathsaey.stoofnogaan.R; +import be.mathsaey.stoofnogaan.data.Task; + +class TaskView extends LinearLayout { + private Task task; + + private MainActivity parent; + + protected CheckBox checkBox; + protected EditText textView; + + public TaskView(MainActivity p, Task t) { + super(p); + task = t; + + LayoutInflater.from(p).inflate(R.layout.task, this); + + parent = p; + checkBox = findViewById(R.id.checkBox); + textView = findViewById(R.id.textView); + + checkBox.setChecked(t.getStatus()); + textView.setText(t.getText()); + + addTextListeners(); + } + + public void update() { + task.setText(textView.getText().toString()); + task.setStatus(checkBox.isChecked()); + } + + public Task getTask() { + return this.task; + } + + // Android is horrible, this code tries to figure out when the user finished editing. + // When this is the case, check if the text field is empty, delete the taskview if this is + // the case. + private void addTextListeners() { + // Update text when text is changed + textView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + + @Override + public void afterTextChanged(Editable editable) { + TaskView.this.update(); + if (task.isEmpty()) { + parent.deleteTask(TaskView.this); + } + } + }); + } +} diff --git a/app/src/main/res/drawable/button.xml b/app/src/main/res/drawable/button.xml index 75571bf..a348eec 100644 --- a/app/src/main/res/drawable/button.xml +++ b/app/src/main/res/drawable/button.xml @@ -7,7 +7,7 @@ + android:color="#7c7656" /> - + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 9649b94..bc7a999 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,8 +7,7 @@ android:orientation="vertical" android:background="@color/colorLight" android:padding="52dp" - android:paddingTop="102dp" - tools:context="be.mathsaey.stoofnogaan.MainActivity"> + tools:context="ui.MainActivity"> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cef5b63..30ddab1 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,7 +3,7 @@ #FFF #FFF8E1 #FF7F2A - #5FD3BC + #5FD3BC #E6DDBF #552200 diff --git a/designs/header.png b/designs/header.png new file mode 100644 index 0000000..d8e939a Binary files /dev/null and b/designs/header.png differ diff --git a/designs/homescreen-icon.svg b/designs/homescreen-icon.svg new file mode 100644 index 0000000..7f29c8d --- /dev/null +++ b/designs/homescreen-icon.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/designs/in-app-icon.svg b/designs/in-app-icon.svg new file mode 100644 index 0000000..ee9894e --- /dev/null +++ b/designs/in-app-icon.svg @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + Stoof In Brand? + Moogt ge weg gaan alle? + + + + + + + + + + + + + + +