Skip to content

Commit f60a0f0

Browse files
committed
Search feature added
1 parent b6446a0 commit f60a0f0

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

app/src/main/java/edu/sharif/homework1/AddToClassFragment.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,23 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
6060
adapter.setClickListener(this);
6161
recyclerView.setAdapter(adapter);
6262

63+
binding.addClass.setOnClickListener(view1 -> {
64+
String searchText = binding.className.getText().toString();
65+
if (searchText.isEmpty()) {
66+
Toast.makeText(getContext(), "Please enter a class name", Toast.LENGTH_SHORT).show();
67+
} else if (!classesName.contains(searchText)) {
68+
Toast.makeText(getContext(), "Class not found", Toast.LENGTH_SHORT).show();
69+
} else {
70+
addToClass(searchText);
71+
}
72+
});
73+
}
6374

75+
private void addToClass(String searchText) {
76+
Class newClass = Class.getClassByName(searchText);
77+
newClass.getStudents().add(student);
78+
student.getClasses().add(newClass);
79+
Toast.makeText(getContext(), "you added to this class!", Toast.LENGTH_SHORT).show();
6480
}
6581

6682

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,39 @@
77
tools:context=".AddToClassFragment">
88

99

10+
<Button
11+
android:id="@+id/addClass"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:text="@string/search"
15+
app:layout_constraintBottom_toTopOf="@+id/classes_list"
16+
app:layout_constraintEnd_toEndOf="parent"
17+
app:layout_constraintHorizontal_bias="0.089"
18+
app:layout_constraintStart_toEndOf="@+id/className"
19+
app:layout_constraintTop_toTopOf="parent"
20+
app:layout_constraintVertical_bias="0.0" />
21+
22+
<EditText
23+
android:id="@+id/className"
24+
android:layout_width="145dp"
25+
android:layout_height="wrap_content"
26+
android:ems="10"
27+
android:hint="@string/class_name"
28+
android:inputType="textPersonName"
29+
app:layout_constraintBottom_toBottomOf="parent"
30+
app:layout_constraintEnd_toEndOf="parent"
31+
app:layout_constraintHorizontal_bias="0.0"
32+
app:layout_constraintStart_toStartOf="parent"
33+
app:layout_constraintTop_toTopOf="parent"
34+
app:layout_constraintVertical_bias="0.0" />
35+
1036
<androidx.recyclerview.widget.RecyclerView
1137
android:id="@+id/classes_list"
1238
android:layout_width="0dp"
1339
android:layout_height="0dp"
1440
app:layout_constraintBottom_toBottomOf="parent"
1541
app:layout_constraintEnd_toEndOf="parent"
1642
app:layout_constraintStart_toStartOf="parent"
17-
app:layout_constraintTop_toTopOf="parent"
43+
app:layout_constraintTop_toBottomOf="@+id/className"
1844
app:layout_constraintVertical_bias="0" />
1945
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)