Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'org.naishadhparmar.zcustomcalendar:zcustomcalendar:1.0.1'
implementation 'com.github.Armen101:AudioRecordView:1.0.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,99 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import org.naishadhparmar.zcustomcalendar.CustomCalendar;
import org.naishadhparmar.zcustomcalendar.OnDateSelectedListener;
import org.naishadhparmar.zcustomcalendar.Property;

import java.util.Calendar;
import java.util.HashMap;

import ca.uwaterloo.sentimo.R;

public class CalendarFragment extends Fragment {

private CalendarViewModel calendarViewModel;
CustomCalendar customCalendar;

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
calendarViewModel =
new ViewModelProvider(this).get(CalendarViewModel.class);
View root = inflater.inflate(R.layout.fragment_calendar, container, false);
final TextView textView = root.findViewById(R.id.text_calendar);
calendarViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

//Assign variable
customCalendar = view.findViewById(R.id.custom_calendar);

//Initialize description hash map
HashMap<Object, Property> descHashMap = new HashMap<>();
//Initialize default property
Property defaultProperty = new Property();
//Initialize default resource
defaultProperty.layoutResource = R.layout.default_view;
//Initialize and assign variable
defaultProperty.dateTextViewResource = R.id.text_view;
//Put object and property
descHashMap.put("default", defaultProperty);

//For current date
Property currentProperty = new Property();
currentProperty.layoutResource = R.layout.current_view;
currentProperty.dateTextViewResource = R.id.text_view;
descHashMap.put("current", currentProperty);

//For Present date
Property presentProperty = new Property();
presentProperty.layoutResource = R.layout.present_view;
presentProperty.dateTextViewResource = R.id.text_view;
descHashMap.put("present", presentProperty);

//For absent
Property absentProperty = new Property();
absentProperty.layoutResource = R.layout.absent_view;
absentProperty.dateTextViewResource = R.id.text_view;
descHashMap.put("absent", absentProperty);

//Set desc hash map on custom calendar
customCalendar.setMapDescToProp(descHashMap);

//Initialize date hash map
HashMap<Integer, Object> dateHashMap = new HashMap<>();
//Initialize calendar
Calendar calendar = Calendar.getInstance();
//Put values
dateHashMap.put(calendar.get(Calendar.DAY_OF_MONTH), "current");
dateHashMap.put(1, "present");
dateHashMap.put(2, "absent");
dateHashMap.put(3, "present");
dateHashMap.put(4, "absent");
dateHashMap.put(20, "present");
dateHashMap.put(30, "absent");
//Set date
customCalendar.setDate(calendar, dateHashMap);

customCalendar.setOnDateSelectedListener(new OnDateSelectedListener() {
@Override
public void onChanged(@Nullable String s) {
textView.setText(s);
public void onDateSelected(View view, Calendar selectedDate, Object desc) {
//Get string date
String sDate = selectedDate.get(Calendar.DAY_OF_MONTH)
+ "/" + (selectedDate.get(Calendar.MONTH) + 1 )
+ "/" + selectedDate.get(Calendar.YEAR);
//Display date in toast
Toast.makeText(getActivity().getApplicationContext()
, sDate, Toast.LENGTH_SHORT).show();
}
});
}

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {

View root = inflater.inflate(R.layout.fragment_calendar, container, false);

return root;

}
}

This file was deleted.

26 changes: 26 additions & 0 deletions app/src/main/res/layout/absent_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_margin = "2dp"
android:padding="2dp">

<androidx.cardview.widget.CardView
android:layout_width = "40dp"
android:layout_height = "32dp"
android:layout_margin = "4dp"
app:cardCornerRadius = "4dp"
app:cardBackgroundColor="@android:color/holo_red_light">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id = "@+id/text_view"
android:textColor="@color/white"
android:gravity="center"/>

</androidx.cardview.widget.CardView>

</RelativeLayout>
26 changes: 26 additions & 0 deletions app/src/main/res/layout/current_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_margin = "2dp"
android:padding="2dp">

<androidx.cardview.widget.CardView
android:layout_width = "40dp"
android:layout_height = "32dp"
android:layout_margin = "4dp"
app:cardCornerRadius = "4dp"
app:cardBackgroundColor="@android:color/holo_blue_light">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id = "@+id/text_view"
android:textColor="@color/white"
android:gravity="center"/>

</androidx.cardview.widget.CardView>

</RelativeLayout>
25 changes: 25 additions & 0 deletions app/src/main/res/layout/default_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_margin = "2dp"
android:padding="2dp">

<androidx.cardview.widget.CardView
android:layout_width = "40dp"
android:layout_height = "32dp"
android:layout_margin = "4dp"
app:cardCornerRadius = "4dp">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id = "@+id/text_view"
android:textColor="@color/black"
android:gravity="center"/>

</androidx.cardview.widget.CardView>

</RelativeLayout>
16 changes: 5 additions & 11 deletions app/src/main/res/layout/fragment_calendar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
android:layout_height="match_parent"
tools:context=".ui.calendar.CalendarFragment">

<TextView
android:id="@+id/text_calendar"
<org.naishadhparmar.zcustomcalendar.CustomCalendar
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
android:id = "@+id/custom_calendar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
26 changes: 26 additions & 0 deletions app/src/main/res/layout/present_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_margin = "2dp"
android:padding="2dp">

<androidx.cardview.widget.CardView
android:layout_width = "40dp"
android:layout_height = "32dp"
android:layout_margin = "4dp"
app:cardCornerRadius = "4dp"
app:cardBackgroundColor="@android:color/holo_green_light">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id = "@+id/text_view"
android:textColor="@color/white"
android:gravity="center"/>

</androidx.cardview.widget.CardView>

</RelativeLayout>