Skip to content

Commit 425833a

Browse files
committed
Update
Updated some code added checklist (not fully working)
1 parent f7647a3 commit 425833a

15 files changed

Lines changed: 391 additions & 19 deletions

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.btn.pronotes"
1111
minSdk 21
1212
targetSdk 33
13-
versionCode 1
14-
versionName "1.0"
13+
versionCode 2
14+
versionName "2.0"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
android:exported="false"
2626
android:label="@string/title_activity_drawing"
2727
android:theme="@style/Theme.ProNotes.NoActionBar" />
28+
<activity android:name=".ChecklistActivity" />
29+
<activity
30+
android:name=".ChecklistNotesActivity"
31+
android:label="Checklist Notes" />
2832
<activity
2933
android:name=".FolderActivity"
3034
android:exported="false" />

app/src/main/java/com/btn/pronotes/Adapters/NotesListAdapter.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import androidx.cardview.widget.CardView;
1717
import androidx.recyclerview.widget.RecyclerView;
1818

19+
import com.btn.pronotes.ChecklistItem;
1920
import com.btn.pronotes.Models.Notes;
2021
import com.btn.pronotes.NotesClickListener;
2122
import com.btn.pronotes.R;
@@ -31,6 +32,7 @@ public class NotesListAdapter extends RecyclerView.Adapter<NotesViewHolder> {
3132
List<Notes> list;
3233
NotesClickListener listener;
3334

35+
3436
public NotesListAdapter(Context context, List<Notes> list, NotesClickListener listener) {
3537
this.context = context;
3638
this.list = list;
@@ -140,4 +142,29 @@ public NotesViewHolder(@NonNull View itemView) {
140142
textView_date = itemView.findViewById(R.id.textView_date);
141143
imageView_pin = itemView.findViewById(R.id.imageView_pin);
142144
}
145+
public class Notes {
146+
// Existing fields
147+
148+
private List<ChecklistItem> checklistItems;
149+
150+
public Notes() {
151+
// Existing constructor code
152+
checklistItems = new ArrayList<>();
153+
}
154+
155+
// Existing getter and setter methods
156+
157+
public List<ChecklistItem> getChecklistItems() {
158+
return checklistItems;
159+
}
160+
161+
public void setChecklistItems(List<ChecklistItem> checklistItems) {
162+
this.checklistItems = checklistItems;
163+
}
164+
165+
public void addChecklistItem(ChecklistItem item) {
166+
checklistItems.add(item);
167+
}
168+
}
169+
143170
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.btn.pronotes;
2+
3+
import android.content.Intent;
4+
import android.view.View;
5+
6+
import androidx.appcompat.app.AppCompatActivity;
7+
8+
public class ChecklistActivity extends AppCompatActivity {
9+
// Existing code
10+
11+
public void openChecklistNotes(View view) {
12+
Intent intent = new Intent(this, ChecklistNotesActivity.class);
13+
startActivity(intent);
14+
}
15+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.btn.pronotes;
2+
3+
import android.view.LayoutInflater;
4+
import android.view.View;
5+
import android.view.ViewGroup;
6+
import android.widget.CheckBox;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.recyclerview.widget.RecyclerView;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
public class ChecklistAdapter extends RecyclerView.Adapter<ChecklistAdapter.ChecklistViewHolder> {
15+
16+
private List<String> checklistItems;
17+
18+
public ChecklistAdapter() {
19+
checklistItems = new ArrayList<>();
20+
}
21+
22+
public void setChecklistItems(List<String> items) {
23+
checklistItems.clear();
24+
if (items != null) {
25+
checklistItems.addAll(items);
26+
}
27+
notifyDataSetChanged();
28+
}
29+
30+
@NonNull
31+
@Override
32+
public ChecklistViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
33+
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_checklist, parent, false);
34+
return new ChecklistViewHolder(itemView);
35+
}
36+
37+
@Override
38+
public void onBindViewHolder(@NonNull ChecklistViewHolder holder, int position) {
39+
String item = checklistItems.get(position);
40+
holder.bindItem(item);
41+
}
42+
43+
@Override
44+
public int getItemCount() {
45+
return checklistItems.size();
46+
}
47+
48+
public class ChecklistViewHolder extends RecyclerView.ViewHolder {
49+
50+
private CheckBox checkBox;
51+
52+
public ChecklistViewHolder(@NonNull View itemView) {
53+
super(itemView);
54+
checkBox = itemView.findViewById(R.id.checkBox_item);
55+
}
56+
57+
public void bindItem(String item) {
58+
checkBox.setText(item);
59+
}
60+
}
61+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.btn.pronotes;
2+
3+
public class ChecklistItem {
4+
private String text;
5+
private boolean isChecked;
6+
7+
public ChecklistItem(String text, boolean isChecked) {
8+
this.text = text;
9+
this.isChecked = isChecked;
10+
}
11+
12+
public String getText() {
13+
return text;
14+
}
15+
16+
public void setText(String text) {
17+
this.text = text;
18+
}
19+
20+
public boolean isChecked() {
21+
return isChecked;
22+
}
23+
24+
public void setChecked(boolean checked) {
25+
isChecked = checked;
26+
}
27+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package com.btn.pronotes;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.view.View;
6+
import android.widget.EditText;
7+
8+
import androidx.appcompat.app.AppCompatActivity;
9+
import androidx.recyclerview.widget.LinearLayoutManager;
10+
import androidx.recyclerview.widget.RecyclerView;
11+
12+
import com.btn.pronotes.Models.Notes;
13+
import com.google.android.material.floatingactionbutton.FloatingActionButton;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
19+
public class ChecklistNotesActivity extends AppCompatActivity {
20+
21+
private EditText editTextChecklistItem;
22+
private RecyclerView recyclerViewChecklist;
23+
private FloatingActionButton fabAddChecklistItem;
24+
25+
private List<String> checklistItems;
26+
private ChecklistAdapter checklistAdapter;
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
32+
setContentView(R.layout.activity_checklist_notes);
33+
editTextChecklistItem = findViewById(R.id.editText_checklist_item);
34+
recyclerViewChecklist = findViewById(R.id.rv_checklist);
35+
fabAddChecklistItem = findViewById(R.id.fab_add_checklist_item);
36+
checklistItems = new ArrayList<>();
37+
checklistItems.add("Option 1");
38+
checklistItems.add("Option 2");
39+
checklistItems.add("Option 3");
40+
41+
checklistAdapter = new ChecklistAdapter();
42+
recyclerViewChecklist.setLayoutManager(new LinearLayoutManager(this));
43+
recyclerViewChecklist.setAdapter(checklistAdapter);
44+
fabAddChecklistItem.setOnClickListener(new View.OnClickListener() {
45+
46+
@Override
47+
public void onClick(View v) {
48+
addChecklistItem();
49+
}
50+
});
51+
52+
// Get the checklist items passed from the previous activity
53+
Intent intent = getIntent();
54+
if (intent != null) {
55+
List<String> items = intent.getStringArrayListExtra("checklistItems");
56+
if (items != null) {
57+
checklistItems.addAll(items);
58+
}
59+
}
60+
checklistAdapter.setChecklistItems(checklistItems);
61+
}
62+
63+
64+
65+
private void addChecklistItem() {
66+
String item = editTextChecklistItem.getText().toString().trim();
67+
if (!item.isEmpty()) {
68+
checklistItems.add(item);
69+
checklistAdapter.setChecklistItems(checklistItems);
70+
editTextChecklistItem.setText("");
71+
}
72+
}
73+
74+
private void saveChecklistAsNote() {
75+
// Create a new note object
76+
String title = "Checklist Note";
77+
StringBuilder content = new StringBuilder();
78+
for (String item : checklistItems) {
79+
content.append("- ").append(item).append("\n");
80+
}
81+
82+
// Finish the activity and return to the previous activity
83+
setResult(RESULT_OK);
84+
finish();
85+
}
86+
87+
@Override
88+
public void onBackPressed() {
89+
saveChecklistAsNote();
90+
super.onBackPressed();
91+
}
92+
93+
private void saveNote() {
94+
int index = 1; // Set the desired index value
95+
96+
// Create a new Notes object with the index
97+
Notes note = new Notes();
98+
99+
// Save the note to your data storage or database
100+
// Example:
101+
// NoteDatabase.save(note);
102+
103+
// Finish the activity and return to the previous activity
104+
setResult(RESULT_OK);
105+
finish();
106+
}
107+
108+
@Override
109+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
110+
super.onActivityResult(requestCode, resultCode, data);
111+
if (requestCode == 101 && resultCode == RESULT_OK) {
112+
// Update the checklist items if any changes were made in the ChecklistActivity
113+
List<String> updatedItems = data.getStringArrayListExtra("checklistItems");
114+
if (updatedItems != null) {
115+
checklistItems.clear();
116+
checklistItems.addAll(updatedItems);
117+
checklistAdapter.setChecklistItems(checklistItems);
118+
}
119+
}
120+
}
121+
}

app/src/main/java/com/btn/pronotes/FolderActivity.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
import static com.btn.pronotes.MainActivity.FOLDER_REQUEST_CODE;
55
import static com.btn.pronotes.utils.CONSTANTS.NOTE;
66

7-
import androidx.appcompat.app.AlertDialog;
8-
import androidx.appcompat.app.AppCompatActivity;
9-
import androidx.cardview.widget.CardView;
10-
117
import android.content.Intent;
128
import android.os.Bundle;
13-
import android.view.KeyEvent;
14-
import android.widget.PopupMenu;
9+
10+
import androidx.appcompat.app.AlertDialog;
11+
import androidx.appcompat.app.AppCompatActivity;
1512

1613
import com.btn.pronotes.Adapters.FolderListAdapter;
1714
import com.btn.pronotes.Database.RoomDB;
@@ -48,9 +45,30 @@ protected void onCreate(Bundle savedInstanceState) {
4845
isChangeFolderEnabled = true;
4946
note = (Notes) getIntent().getSerializableExtra(NOTE);
5047
}
48+
// Retrieve the noteType from Intent extras
49+
int noteType = getIntent().getIntExtra("noteType", 1); // Use 1 as the default note type (e.g., text)
50+
51+
if (noteType == 2) {
52+
// Handle checklist note creation
53+
// You can set appropriate flags or variables to indicate that it's a checklist note
54+
// For example, you can display a different UI for checklist notes or perform checklist-specific operations
55+
// You can also store the note type in a member variable for future reference
56+
57+
// Create a default checklist with items
58+
List<String> checklistItems = new ArrayList<>();
59+
checklistItems.add("Item 1");
60+
checklistItems.add("Item 2");
61+
checklistItems.add("Item 3");
62+
63+
// TODO: Add code to populate the checklist UI with the default items
64+
// You need to update your UI accordingly to display the checklist and its items
65+
} else {
66+
// Handle other note types (e.g., text note)
67+
// You can have different logic or behavior for non-checklist notes here
68+
}
5169
}
5270

53-
private void setupFolderRecyclerView() {
71+
private void setupFolderRecyclerView() {
5472

5573
List<Folder> folders = new ArrayList<>(database.mainDAO().getAllFolder());
5674

app/src/main/java/com/btn/pronotes/MainActivity.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,12 @@ protected void onCreate(Bundle savedInstanceState) {
116116
updateRecycler(notes);
117117

118118
btnListener();
119+
fabOptionCheckList.setOnClickListener(v -> {
120+
Intent intent = new Intent(MainActivity.this, ChecklistNotesActivity.class);
121+
intent.putExtra("noteType", 2); // Use 2 to represent checklist note type
122+
startActivityForResult(intent, 101);
123+
});
119124

120-
// fab_add.setOnClickListener(new View.OnClickListener() {
121-
// @Override
122-
// public void onClick(View v) {
123-
// Intent intent = new Intent(MainActivity.this, NotesTakerActivity.class);
124-
// startActivityForResult(intent, 101); // adding note 101
125-
// }
126-
// });
127125

128126
// Implements the drag and drop movement of the notes
129127
ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT | ItemTouchHelper.START | ItemTouchHelper.END, 0) {
@@ -209,6 +207,10 @@ private void btnListener() {
209207
startActivityForResult(intent, 101); // adding note 101
210208
});
211209

210+
fabOptionCheckList.setOnClickListener(v -> {
211+
Intent intent = new Intent(MainActivity.this, NotesTakerActivity.class);
212+
startActivityForResult(intent, 101); });
213+
212214
fabOptionDraw.setOnClickListener(view -> {
213215
Intent intent = new Intent(MainActivity.this, DrawingActivity.class);
214216
intent.putExtra("FROM", "main screen");

0 commit comments

Comments
 (0)