assignment#1
assignment#1
UI Components:
RecyclerView: An advanced and flexible version of ListView, RecyclerView is designed to
display large datasets efficiently by recycling views that are no longer visible to the user. This is
ideal for a list of students, as it ensures smooth scrolling and optimal performance.
CheckBox: Each item in the RecyclerView will include a CheckBox to allow teachers to mark
students as present or absent. This provides a clear and intuitive interface for attendance marking.
Button: A Button labeled "Submit" or "Save" will be placed at the bottom of the screen to allow
teachers to finalize and save the attendance records.
TextView: Used within each RecyclerView item to display the student's name and possibly
additional information like roll number or profile picture.
Layout Structure:
Parent Layout: Utilize a ConstraintLayout as the root layout for the activity. ConstraintLayout
allows for flexible and efficient placement of UI elements, reducing the need for nested layouts
and improving performance.
RecyclerView Item Layout: Each item in the RecyclerView can be structured using a
LinearLayout with horizontal orientation, containing:
ImageView: Optional, for displaying the student's profile picture.
TextView: To display the student's name.
CheckBox: To mark attendance.
Purpose:
This is the landing screen for teachers. It displays the list of students and allows marking each
student as present or absent.
UI Components likely used:
RecyclerView for the list, with each item having TextView (student name) and ToggleButton or
CheckBox (for marking present/absent).
Data Sent/Received:
Could store and pass updated attendance data to another screen via Bundle.
Purpose:
Displays past attendance records and percentage for each student, likely in a scrollable list or
chart.
UI Components:
RecyclerView, ProgressBar, TextView, or a ChartView.
Data Sent/Received:
Might receive the student list and their attendance records via Intent or a local database.
Could use Bundle to pass filters like date range or class section.
3. StudentDetailActivity (Optional)
Purpose:
Shows detailed attendance stats for an individual student (e.g., total days present/absent,
percentage, attendance trend).
Data Sent/Received:
4. AddStudentActivity
Purpose:
Allows the teacher to add new students to the list.
Data Sent/Received:
Sends new student info back to MainActivity via Intent or setResult() when finished.
Explanation:
studentId: A unique identifier for each student, used to distinguish records in the database.
name: The full name of the student, displayed in the UI.
isPresent: A mutable Boolean indicating the student's attendance status for the current session.
Usage:
List Management: Maintain a mutable list of StudentAttendance objects to represent the current
attendance session.
val attendanceList = mutableListOf<StudentAttendance>()
Updating Records: When a teacher marks a student as present or absent, update the
corresponding object's isPresent property.
attendanceList.find { it.studentId == "123" }?.isPresent = true
Data Persistence: Upon submission, iterate through the list and save each record to the local
database or send it to the server.
for (record in attendanceList) {
Advantages:
Easy Access: Using studentId as a key allows for quick retrieval and updates of specific records.
Mutable State: The isPresent property can be easily toggled based on user interaction.
Scalability: The structure supports additional fields (e.g., date, classId) as needed for more
complex scenarios.
Q4: XML Drawable Shape for Custom Green “Present” Button
Drawable XML (res/drawable/green_button.xml):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#4CAF50" /> <!-- Green color -->
<padding
android:left="12dp"
android:top="8dp"
android:right="12dp"
android:bottom="8dp" /></shape>
android:id="@+id/btnPresent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/green_button"
android:text="Present"
android:textColor="#FFFFFF" />
Explanation:
<shape>: Defines the drawable as a rectangle shape.
<solid>: Sets the fill color of the shape to a specific shade of green (#4CAF50).
<corners>: Applies a corner radius of 8dp to create rounded corners, enhancing the button's appearance.
<padding>: Adds internal spacing within the button to ensure the text is not cramped.
Problem: Displaying a large number of students can lead to performance issues, such as slow
scrolling and increased memory usage.
Solution:
RecyclerView with ViewHolder Pattern: RecyclerView efficiently recycles views that are no
longer visible, minimizing memory usage. The ViewHolder pattern further optimizes
performance by reducing unnecessary findViewById calls.
Pagination or Lazy Loading: Implement pagination to load and display a subset of students at a
time, reducing the initial load time and resource consumption.
Efficient Data Structures: Use appropriate data structures (e.g., HashMap) for quick access and
updates to student records.
Challenge#2:
Preserving Attendance State on Configuration Changes
Problem: Configuration changes, such as screen rotations, can cause the activity to be
destroyed and recreated, leading to loss of unsaved attendance data.
Solution:
ViewModel: Utilize Android's ViewModel architecture component to store and manage UI-
related data in a lifecycle-conscious way. ViewModel survives configuration changes, ensuring
that the attendance data remains intact.
onSaveInstanceState(): Override this method to save the current state of the attendance list into a
Bundle. Restore the data in onCreate() or onRestoreInstanceState() during activity recreation.
Persistent Storage: Periodically save the attendance data to persistent storage (e.g.,
SharedPreferences or a local database) to prevent data loss in case of unexpected app termination.
Challenge#3:
Data Persistence and Offline Access
Problem: Teachers may need to access and record attendance without a reliable internet
connection.
Solution:
Room Database: Implement Room, Android's persistence library, to store attendance data locally.
This allows the app to function offline and ensures data is not lost.
Data Synchronization: When the device regains internet connectivity, synchronize the local data
with the remote server to ensure consistency across.