Skip to content
This repository was archived by the owner on Nov 4, 2023. It is now read-only.

Commit 669abeb

Browse files
committed
Strikethrough completed tasks on home activity
* Implement ExpandableJottingsListAdapter.ChildViewHolder#displayStrikethrough() (same implementation as the method in AppBarFragment) * Show whether jotting is marked as completed with a strikethrough - invoke displayStrikethrough() in bindView() * Add shared notes and shared tasks more cleanly to data pump * Implement JSONToModel#convertJSONToNotes() - same purpose and implementation as convertJSONToTasks() but for notes * Go back to OrangeGradientButton on login screen * Add whether a Task is marked as complete to its string representation v2.3.2
1 parent 4fce6f1 commit 669abeb

8 files changed

Lines changed: 51 additions & 12 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.boruminc.borumjot.android"
99
minSdkVersion 16
1010
targetSdkVersion 29
11-
versionCode 50
12-
versionName "2.3.1"
11+
versionCode 51
12+
versionName "2.3.2"
1313

1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515
}

app/src/main/java/com/boruminc/borumjot/Task.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public Task(String n, String b, ArrayList<Label> labels) {
3030

3131
@NonNull
3232
public String toString() {
33-
return super.toString();
33+
String str = super.toString();
34+
str += "Completed: " + completed;
35+
36+
return str;
3437
}
3538

3639
@Override

app/src/main/java/com/boruminc/borumjot/android/AppBarFragment.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ void passTitleLeftAligned(String titleTxt) {
4747
void displayStrikethrough(boolean on) {
4848
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
4949
if (on)
50-
// Add a strikethrough to the already existing paint flags using "|" bitwise operator
5150
title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
5251
else
53-
// Remove the strikethrough from the paint flags using "&" bitwise operator
5452
title.setPaintFlags(title.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
5553
}
5654
}

app/src/main/java/com/boruminc/borumjot/android/ExpandableJottingsListAdapter.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.graphics.Color;
7+
import android.graphics.Paint;
78
import android.graphics.Typeface;
89
import android.graphics.drawable.Drawable;
910
import android.os.Build;
1011
import android.os.Bundle;
12+
import android.util.Log;
1113
import android.view.LayoutInflater;
1214
import android.view.View;
1315
import android.view.ViewGroup;
@@ -199,12 +201,29 @@ public void setViewProperties(View v) {
199201
textView.setPadding(padding, padding, 0, padding);
200202
}
201203

204+
/**
205+
* Sets a strikethrough on the title by adding a background
206+
* @param on Whether to strikethrough or remove strikethrough
207+
*/
208+
void displayStrikethrough(boolean on) {
209+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
210+
if (on)
211+
textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
212+
else
213+
textView.setPaintFlags(textView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
214+
}
215+
}
216+
202217
@Override
203218
public void bindView(Object data) {
204219
Jotting jottingInst = (Jotting) data;
205220
textView.setText(jottingInst.getName());
206221
textView.setTag(jottingInst);
207222
pinIcon.setVisibility(jottingInst.getPriority() > 0 ? View.VISIBLE : View.INVISIBLE);
223+
224+
// Indicate whether the task is marked as complete to give the priority property meaning
225+
boolean completed = data instanceof Task && ((Task) textView.getTag()).isCompleted();
226+
displayStrikethrough(completed);
208227
}
209228

210229
/**

app/src/main/java/com/boruminc/borumjot/android/HomeActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,12 @@ public void onComplete(JSONObject result) {
211211
if (ranOk()) {
212212
JSONObject groupedData = result.getJSONObject("data");
213213

214-
ArrayList<Jotting> jottings = JSONToModel.convertJSONToJottings(groupedData.getJSONArray("notes"));
215-
ArrayList<Jotting> tasks = JSONToModel.convertJSONToJottings(groupedData.getJSONArray("tasks"));
214+
ArrayList<Note> notes = JSONToModel.convertJSONToNotes(groupedData.getJSONArray("notes"));
215+
ArrayList<Task> tasks = JSONToModel.convertJSONToTasks(groupedData.getJSONArray("tasks"));
216216

217+
ArrayList<Jotting> jottings = new ArrayList<>(notes);
217218
jottings.addAll(tasks);
219+
218220
jotListData.setSharedData(jottings);
219221
jottingsListAdapter.setSharedData(jotListData.getSharedData());
220222
jottingsListAdapter.notifyDataSetChanged();

app/src/main/java/com/boruminc/borumjot/android/server/JSONToModel.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public static ArrayList<Jotting> convertJSONToJottings(JSONArray jottingsData) t
3030

3131
if (row.getString("source").equals("note"))
3232
jottings.add(convertJSONToNote(row));
33-
else if (row.getString("source").equals("task"))
33+
else if (row.getString("source").equals("task")) {
3434
jottings.add(convertJSONToTask(row));
35+
}
3536
}
3637

3738
return jottings;
@@ -45,12 +46,28 @@ else if (row.getString("source").equals("task"))
4546
*/
4647
public static ArrayList<Task> convertJSONToTasks(JSONArray data) throws JSONException {
4748
ArrayList<Task> tasks = new ArrayList<Task>();
48-
for (int i = 0; i < data.length(); i++)
49+
for (int i = 0; i < data.length(); i++) {
4950
tasks.add(convertJSONToTask(data.getJSONObject(i)));
51+
}
5052

5153
return tasks;
5254
}
5355

56+
/**
57+
* Converts a <code>JSONArray</code> of <code>JSONObject</code>s to a <code>Task</code> object
58+
* @param data The JSONArray
59+
* @return A list of Tasks corresponding to the JSON data
60+
* @throws JSONException if the id or title is not given for any row
61+
*/
62+
public static ArrayList<Note> convertJSONToNotes(JSONArray data) throws JSONException {
63+
ArrayList<Note> notes = new ArrayList<>();
64+
for (int i = 0; i < data.length(); i++) {
65+
notes.add(convertJSONToNote(data.getJSONObject(i)));
66+
}
67+
68+
return notes;
69+
}
70+
5471
private static Task convertJSONToTask(JSONObject row) throws JSONException {
5572
// Set task information
5673
Task task = new Task(row.getString("title"), row.optString("body"), new ArrayList<Label>());

app/src/main/res/layout/activity_login.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
app:layout_constraintTop_toBottomOf="@+id/password"
6868
app:layout_constraintBottom_toTopOf="@id/borumjot_affil_note">
6969

70-
<Button
70+
<com.boruminc.borumjot.android.customviews.OrangeGradientButton
7171
android:id="@+id/login"
7272
style="@style/OneSelectButtonGradient"
7373
android:enabled="true"
7474
android:onClick="submitLogin"
7575
android:text="@string/action_sign_in" />
7676

77-
<Button
77+
<com.boruminc.borumjot.android.customviews.OrangeGradientButton
7878
android:id="@+id/registernavbtn"
7979
style="@style/OneSelectButtonGradient"
8080
android:onClick="navToRegister"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<string name="delete_content_desc">Trashcan or delete icon</string>
9393
<string name="save_content_desc">Save icon</string>
9494
<string name="action_help">Help</string>
95-
<string name="version_name">Version 2.3.1</string>
95+
<string name="version_name">Version 2.3.2</string>
9696
<string name="action_labels">Labels</string>
9797
<string name="copyright_notice">Copyright 2021 Varun Singh</string>
9898
<string name="support_email">support@borumtech.com</string>

0 commit comments

Comments
 (0)