diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..9449b0d
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+CalendarAppExample
\ No newline at end of file
diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..74a10cc
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 23a89bb..2c7e034 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,7 +4,7 @@
-
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d5d35ec..c8346b4 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,16 @@
+
+
+
+
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2bcd16f..546cc94 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -9,6 +9,11 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CalendarAppExample">
+
+
+
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/CalendarAdapter.java b/app/src/main/java/codewithcal/au/calendarappexample/CalendarAdapter.java
index 92b7ec5..7a4e668 100644
--- a/app/src/main/java/codewithcal/au/calendarappexample/CalendarAdapter.java
+++ b/app/src/main/java/codewithcal/au/calendarappexample/CalendarAdapter.java
@@ -1,5 +1,6 @@
package codewithcal.au.calendarappexample;
+import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -7,16 +8,17 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
+import java.time.LocalDate;
import java.util.ArrayList;
class CalendarAdapter extends RecyclerView.Adapter
{
- private final ArrayList daysOfMonth;
+ private final ArrayList days;
private final OnItemListener onItemListener;
- public CalendarAdapter(ArrayList daysOfMonth, OnItemListener onItemListener)
+ public CalendarAdapter(ArrayList days, OnItemListener onItemListener)
{
- this.daysOfMonth = daysOfMonth;
+ this.days = days;
this.onItemListener = onItemListener;
}
@@ -27,24 +29,38 @@ public CalendarViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int view
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.calendar_cell, parent, false);
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
- layoutParams.height = (int) (parent.getHeight() * 0.166666666);
- return new CalendarViewHolder(view, onItemListener);
+ if(days.size() > 15) //month view
+ layoutParams.height = (int) (parent.getHeight() * 0.166666666);
+ else // week view
+ layoutParams.height = (int) parent.getHeight();
+
+ return new CalendarViewHolder(view, onItemListener, days);
}
@Override
public void onBindViewHolder(@NonNull CalendarViewHolder holder, int position)
{
- holder.dayOfMonth.setText(daysOfMonth.get(position));
+ final LocalDate date = days.get(position);
+
+ holder.dayOfMonth.setText(String.valueOf(date.getDayOfMonth()));
+
+ if(date.equals(CalendarUtils.selectedDate))
+ holder.parentView.setBackgroundColor(Color.LTGRAY);
+
+ if(date.getMonth().equals(CalendarUtils.selectedDate.getMonth()))
+ holder.dayOfMonth.setTextColor(Color.BLACK);
+ else
+ holder.dayOfMonth.setTextColor(Color.LTGRAY);
}
@Override
public int getItemCount()
{
- return daysOfMonth.size();
+ return days.size();
}
public interface OnItemListener
{
- void onItemClick(int position, String dayText);
+ void onItemClick(int position, LocalDate date);
}
}
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/CalendarUtils.java b/app/src/main/java/codewithcal/au/calendarappexample/CalendarUtils.java
new file mode 100644
index 0000000..71b9036
--- /dev/null
+++ b/app/src/main/java/codewithcal/au/calendarappexample/CalendarUtils.java
@@ -0,0 +1,102 @@
+package codewithcal.au.calendarappexample;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+
+public class CalendarUtils
+{
+ public static LocalDate selectedDate;
+
+ public static String formattedDate(LocalDate date)
+ {
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy");
+ return date.format(formatter);
+ }
+
+ public static String formattedTime(LocalTime time)
+ {
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm:ss a");
+ return time.format(formatter);
+ }
+
+ public static String formattedShortTime(LocalTime time)
+ {
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
+ return time.format(formatter);
+ }
+
+ public static String monthYearFromDate(LocalDate date)
+ {
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
+ return date.format(formatter);
+ }
+
+ public static String monthDayFromDate(LocalDate date)
+ {
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d");
+ return date.format(formatter);
+ }
+
+ public static ArrayList daysInMonthArray()
+ {
+ ArrayList daysInMonthArray = new ArrayList<>();
+
+ YearMonth yearMonth = YearMonth.from(selectedDate);
+ int daysInMonth = yearMonth.lengthOfMonth();
+
+ LocalDate prevMonth = selectedDate.minusMonths(1);
+ LocalDate nextMonth = selectedDate.plusMonths(1);
+
+ YearMonth prevYearMonth = YearMonth.from(prevMonth);
+ int prevDaysInMonth = prevYearMonth.lengthOfMonth();
+
+ LocalDate firstOfMonth = CalendarUtils.selectedDate.withDayOfMonth(1);
+ int dayOfWeek = firstOfMonth.getDayOfWeek().getValue();
+
+ for(int i = 1; i <= 42; i++)
+ {
+ if(i <= dayOfWeek)
+ daysInMonthArray.add(LocalDate.of(prevMonth.getYear(),prevMonth.getMonth(),prevDaysInMonth + i - dayOfWeek));
+ else if(i > daysInMonth + dayOfWeek)
+ daysInMonthArray.add(LocalDate.of(nextMonth.getYear(),nextMonth.getMonth(),i - dayOfWeek - daysInMonth));
+ else
+ daysInMonthArray.add(LocalDate.of(selectedDate.getYear(),selectedDate.getMonth(),i - dayOfWeek));
+ }
+ return daysInMonthArray;
+ }
+
+ public static ArrayList daysInWeekArray(LocalDate selectedDate)
+ {
+ ArrayList days = new ArrayList<>();
+ LocalDate current = sundayForDate(selectedDate);
+ LocalDate endDate = current.plusWeeks(1);
+
+ while (current.isBefore(endDate))
+ {
+ days.add(current);
+ current = current.plusDays(1);
+ }
+ return days;
+ }
+
+ private static LocalDate sundayForDate(LocalDate current)
+ {
+ LocalDate oneWeekAgo = current.minusWeeks(1);
+
+ while (current.isAfter(oneWeekAgo))
+ {
+ if(current.getDayOfWeek() == DayOfWeek.SUNDAY)
+ return current;
+
+ current = current.minusDays(1);
+ }
+
+ return null;
+ }
+
+
+}
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/CalendarViewHolder.java b/app/src/main/java/codewithcal/au/calendarappexample/CalendarViewHolder.java
index 3867d22..1ceb306 100644
--- a/app/src/main/java/codewithcal/au/calendarappexample/CalendarViewHolder.java
+++ b/app/src/main/java/codewithcal/au/calendarappexample/CalendarViewHolder.java
@@ -6,21 +6,28 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
+import java.time.LocalDate;
+import java.util.ArrayList;
+
public class CalendarViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
{
+ private final ArrayList days;
+ public final View parentView;
public final TextView dayOfMonth;
private final CalendarAdapter.OnItemListener onItemListener;
- public CalendarViewHolder(@NonNull View itemView, CalendarAdapter.OnItemListener onItemListener)
+ public CalendarViewHolder(@NonNull View itemView, CalendarAdapter.OnItemListener onItemListener, ArrayList days)
{
super(itemView);
+ parentView = itemView.findViewById(R.id.parentView);
dayOfMonth = itemView.findViewById(R.id.cellDayText);
this.onItemListener = onItemListener;
itemView.setOnClickListener(this);
+ this.days = days;
}
@Override
public void onClick(View view)
{
- onItemListener.onItemClick(getAdapterPosition(), (String) dayOfMonth.getText());
+ onItemListener.onItemClick(getAdapterPosition(), days.get(getAdapterPosition()));
}
}
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/DailyCalendarActivity.java b/app/src/main/java/codewithcal/au/calendarappexample/DailyCalendarActivity.java
new file mode 100644
index 0000000..2384cb2
--- /dev/null
+++ b/app/src/main/java/codewithcal/au/calendarappexample/DailyCalendarActivity.java
@@ -0,0 +1,94 @@
+package codewithcal.au.calendarappexample;
+
+import static codewithcal.au.calendarappexample.CalendarUtils.selectedDate;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.recyclerview.widget.RecyclerView;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import java.time.LocalTime;
+import java.time.format.TextStyle;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+public class DailyCalendarActivity extends AppCompatActivity
+{
+
+ private TextView monthDayText;
+ private TextView dayOfWeekTV;
+ private ListView hourListView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_daily_calendar);
+ initWidgets();
+ }
+
+ private void initWidgets()
+ {
+ monthDayText = findViewById(R.id.monthDayText);
+ dayOfWeekTV = findViewById(R.id.dayOfWeekTV);
+ hourListView = findViewById(R.id.hourListView);
+ }
+
+ @Override
+ protected void onResume()
+ {
+ super.onResume();
+ setDayView();
+ }
+
+ private void setDayView()
+ {
+ monthDayText.setText(CalendarUtils.monthDayFromDate(selectedDate));
+ String dayOfWeek = selectedDate.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault());
+ dayOfWeekTV.setText(dayOfWeek);
+ setHourAdapter();
+ }
+
+ private void setHourAdapter()
+ {
+ HourAdapter hourAdapter = new HourAdapter(getApplicationContext(), hourEventList());
+ hourListView.setAdapter(hourAdapter);
+ }
+
+ private ArrayList hourEventList()
+ {
+ ArrayList list = new ArrayList<>();
+
+ for(int hour = 0; hour < 24; hour++)
+ {
+ LocalTime time = LocalTime.of(hour, 0);
+ ArrayList events = Event.eventsForDateAndTime(selectedDate, time);
+ HourEvent hourEvent = new HourEvent(time, events);
+ list.add(hourEvent);
+ }
+
+ return list;
+ }
+
+ public void previousDayAction(View view)
+ {
+ CalendarUtils.selectedDate = CalendarUtils.selectedDate.minusDays(1);
+ setDayView();
+ }
+
+ public void nextDayAction(View view)
+ {
+ CalendarUtils.selectedDate = CalendarUtils.selectedDate.plusDays(1);
+ setDayView();
+ }
+
+ public void newEventAction(View view)
+ {
+ startActivity(new Intent(this, EventEditActivity.class));
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/Event.java b/app/src/main/java/codewithcal/au/calendarappexample/Event.java
new file mode 100644
index 0000000..297ba4a
--- /dev/null
+++ b/app/src/main/java/codewithcal/au/calendarappexample/Event.java
@@ -0,0 +1,80 @@
+package codewithcal.au.calendarappexample;
+
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.util.ArrayList;
+
+public class Event
+{
+ public static ArrayList eventsList = new ArrayList<>();
+
+ public static ArrayList eventsForDate(LocalDate date)
+ {
+ ArrayList events = new ArrayList<>();
+
+ for(Event event : eventsList)
+ {
+ if(event.getDate().equals(date))
+ events.add(event);
+ }
+
+ return events;
+ }
+
+ public static ArrayList eventsForDateAndTime(LocalDate date, LocalTime time)
+ {
+ ArrayList events = new ArrayList<>();
+
+ for(Event event : eventsList)
+ {
+ int eventHour = event.time.getHour();
+ int cellHour = time.getHour();
+ if(event.getDate().equals(date) && eventHour == cellHour)
+ events.add(event);
+ }
+
+ return events;
+ }
+
+
+ private String name;
+ private LocalDate date;
+ private LocalTime time;
+
+ public Event(String name, LocalDate date, LocalTime time)
+ {
+ this.name = name;
+ this.date = date;
+ this.time = time;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public LocalDate getDate()
+ {
+ return date;
+ }
+
+ public void setDate(LocalDate date)
+ {
+ this.date = date;
+ }
+
+ public LocalTime getTime()
+ {
+ return time;
+ }
+
+ public void setTime(LocalTime time)
+ {
+ this.time = time;
+ }
+}
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/EventAdapter.java b/app/src/main/java/codewithcal/au/calendarappexample/EventAdapter.java
new file mode 100644
index 0000000..acf084b
--- /dev/null
+++ b/app/src/main/java/codewithcal/au/calendarappexample/EventAdapter.java
@@ -0,0 +1,37 @@
+package codewithcal.au.calendarappexample;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import java.util.List;
+
+public class EventAdapter extends ArrayAdapter
+{
+ public EventAdapter(@NonNull Context context, List events)
+ {
+ super(context, 0, events);
+ }
+
+ @NonNull
+ @Override
+ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent)
+ {
+ Event event = getItem(position);
+
+ if (convertView == null)
+ convertView = LayoutInflater.from(getContext()).inflate(R.layout.event_cell, parent, false);
+
+ TextView eventCellTV = convertView.findViewById(R.id.eventCellTV);
+
+ String eventTitle = event.getName() +" "+ CalendarUtils.formattedTime(event.getTime());
+ eventCellTV.setText(eventTitle);
+ return convertView;
+ }
+}
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/EventEditActivity.java b/app/src/main/java/codewithcal/au/calendarappexample/EventEditActivity.java
new file mode 100644
index 0000000..9c9b365
--- /dev/null
+++ b/app/src/main/java/codewithcal/au/calendarappexample/EventEditActivity.java
@@ -0,0 +1,44 @@
+package codewithcal.au.calendarappexample;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.os.Bundle;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import java.time.LocalTime;
+
+public class EventEditActivity extends AppCompatActivity
+{
+ private EditText eventNameET;
+ private TextView eventDateTV, eventTimeTV;
+
+ private LocalTime time;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_event_edit);
+ initWidgets();
+ time = LocalTime.now();
+ eventDateTV.setText("Date: " + CalendarUtils.formattedDate(CalendarUtils.selectedDate));
+ eventTimeTV.setText("Time: " + CalendarUtils.formattedTime(time));
+ }
+
+ private void initWidgets()
+ {
+ eventNameET = findViewById(R.id.eventNameET);
+ eventDateTV = findViewById(R.id.eventDateTV);
+ eventTimeTV = findViewById(R.id.eventTimeTV);
+ }
+
+ public void saveEventAction(View view)
+ {
+ String eventName = eventNameET.getText().toString();
+ Event newEvent = new Event(eventName, CalendarUtils.selectedDate, time);
+ Event.eventsList.add(newEvent);
+ finish();
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/HourAdapter.java b/app/src/main/java/codewithcal/au/calendarappexample/HourAdapter.java
new file mode 100644
index 0000000..fe6e98a
--- /dev/null
+++ b/app/src/main/java/codewithcal/au/calendarappexample/HourAdapter.java
@@ -0,0 +1,110 @@
+package codewithcal.au.calendarappexample;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import java.time.LocalTime;
+import java.util.ArrayList;
+import java.util.List;
+
+public class HourAdapter extends ArrayAdapter
+{
+ public HourAdapter(@NonNull Context context, List hourEvents)
+ {
+ super(context, 0, hourEvents);
+ }
+
+ @NonNull
+ @Override
+ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent)
+ {
+ HourEvent event = getItem(position);
+
+ if (convertView == null)
+ convertView = LayoutInflater.from(getContext()).inflate(R.layout.hour_cell, parent, false);
+
+ setHour(convertView, event.time);
+ setEvents(convertView, event.events);
+
+ return convertView;
+ }
+
+ private void setHour(View convertView, LocalTime time)
+ {
+ TextView timeTV = convertView.findViewById(R.id.timeTV);
+ timeTV.setText(CalendarUtils.formattedShortTime(time));
+ }
+
+ private void setEvents(View convertView, ArrayList events)
+ {
+ TextView event1 = convertView.findViewById(R.id.event1);
+ TextView event2 = convertView.findViewById(R.id.event2);
+ TextView event3 = convertView.findViewById(R.id.event3);
+
+ if(events.size() == 0)
+ {
+ hideEvent(event1);
+ hideEvent(event2);
+ hideEvent(event3);
+ }
+ else if(events.size() == 1)
+ {
+ setEvent(event1, events.get(0));
+ hideEvent(event2);
+ hideEvent(event3);
+ }
+ else if(events.size() == 2)
+ {
+ setEvent(event1, events.get(0));
+ setEvent(event2, events.get(1));
+ hideEvent(event3);
+ }
+ else if(events.size() == 3)
+ {
+ setEvent(event1, events.get(0));
+ setEvent(event2, events.get(1));
+ setEvent(event3, events.get(2));
+ }
+ else
+ {
+ setEvent(event1, events.get(0));
+ setEvent(event2, events.get(1));
+ event3.setVisibility(View.VISIBLE);
+ String eventsNotShown = String.valueOf(events.size() - 2);
+ eventsNotShown += " More Events";
+ event3.setText(eventsNotShown);
+ }
+ }
+
+ private void setEvent(TextView textView, Event event)
+ {
+ textView.setText(event.getName());
+ textView.setVisibility(View.VISIBLE);
+ }
+
+ private void hideEvent(TextView tv)
+ {
+ tv.setVisibility(View.INVISIBLE);
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/HourEvent.java b/app/src/main/java/codewithcal/au/calendarappexample/HourEvent.java
new file mode 100644
index 0000000..c03d0b4
--- /dev/null
+++ b/app/src/main/java/codewithcal/au/calendarappexample/HourEvent.java
@@ -0,0 +1,36 @@
+package codewithcal.au.calendarappexample;
+
+import java.time.LocalTime;
+import java.util.ArrayList;
+
+class HourEvent
+{
+ LocalTime time;
+ ArrayList events;
+
+ public HourEvent(LocalTime time, ArrayList events)
+ {
+ this.time = time;
+ this.events = events;
+ }
+
+ public LocalTime getTime()
+ {
+ return time;
+ }
+
+ public void setTime(LocalTime time)
+ {
+ this.time = time;
+ }
+
+ public ArrayList getEvents()
+ {
+ return events;
+ }
+
+ public void setEvents(ArrayList events)
+ {
+ this.events = events;
+ }
+}
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/MainActivity.java b/app/src/main/java/codewithcal/au/calendarappexample/MainActivity.java
index 0cf6f4c..200cd53 100644
--- a/app/src/main/java/codewithcal/au/calendarappexample/MainActivity.java
+++ b/app/src/main/java/codewithcal/au/calendarappexample/MainActivity.java
@@ -4,6 +4,7 @@
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
+import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
@@ -14,11 +15,14 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
+import static codewithcal.au.calendarappexample.CalendarUtils.daysInMonthArray;
+import static codewithcal.au.calendarappexample.CalendarUtils.monthYearFromDate;
+
public class MainActivity extends AppCompatActivity implements CalendarAdapter.OnItemListener
{
private TextView monthYearText;
private RecyclerView calendarRecyclerView;
- private LocalDate selectedDate;
+
@Override
protected void onCreate(Bundle savedInstanceState)
@@ -26,7 +30,7 @@ protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initWidgets();
- selectedDate = LocalDate.now();
+ CalendarUtils.selectedDate = LocalDate.now();
setMonthView();
}
@@ -38,8 +42,8 @@ private void initWidgets()
private void setMonthView()
{
- monthYearText.setText(monthYearFromDate(selectedDate));
- ArrayList daysInMonth = daysInMonthArray(selectedDate);
+ monthYearText.setText(monthYearFromDate(CalendarUtils.selectedDate));
+ ArrayList daysInMonth = daysInMonthArray();
CalendarAdapter calendarAdapter = new CalendarAdapter(daysInMonth, this);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(), 7);
@@ -47,57 +51,32 @@ private void setMonthView()
calendarRecyclerView.setAdapter(calendarAdapter);
}
- private ArrayList daysInMonthArray(LocalDate date)
- {
- ArrayList daysInMonthArray = new ArrayList<>();
- YearMonth yearMonth = YearMonth.from(date);
-
- int daysInMonth = yearMonth.lengthOfMonth();
-
- LocalDate firstOfMonth = selectedDate.withDayOfMonth(1);
- int dayOfWeek = firstOfMonth.getDayOfWeek().getValue();
-
- for(int i = 1; i <= 42; i++)
- {
- if(i <= dayOfWeek || i > daysInMonth + dayOfWeek)
- {
- daysInMonthArray.add("");
- }
- else
- {
- daysInMonthArray.add(String.valueOf(i - dayOfWeek));
- }
- }
- return daysInMonthArray;
- }
-
- private String monthYearFromDate(LocalDate date)
- {
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
- return date.format(formatter);
- }
-
public void previousMonthAction(View view)
{
- selectedDate = selectedDate.minusMonths(1);
+ CalendarUtils.selectedDate = CalendarUtils.selectedDate.minusMonths(1);
setMonthView();
}
public void nextMonthAction(View view)
{
- selectedDate = selectedDate.plusMonths(1);
+ CalendarUtils.selectedDate = CalendarUtils.selectedDate.plusMonths(1);
setMonthView();
}
@Override
- public void onItemClick(int position, String dayText)
+ public void onItemClick(int position, LocalDate date)
{
- if(!dayText.equals(""))
+ if(date != null)
{
- String message = "Selected Date " + dayText + " " + monthYearFromDate(selectedDate);
- Toast.makeText(this, message, Toast.LENGTH_LONG).show();
+ CalendarUtils.selectedDate = date;
+ setMonthView();
}
}
+
+ public void weeklyAction(View view)
+ {
+ startActivity(new Intent(this, WeekViewActivity.class));
+ }
}
diff --git a/app/src/main/java/codewithcal/au/calendarappexample/WeekViewActivity.java b/app/src/main/java/codewithcal/au/calendarappexample/WeekViewActivity.java
new file mode 100644
index 0000000..3f66b98
--- /dev/null
+++ b/app/src/main/java/codewithcal/au/calendarappexample/WeekViewActivity.java
@@ -0,0 +1,98 @@
+package codewithcal.au.calendarappexample;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import java.time.LocalDate;
+import java.util.ArrayList;
+
+import static codewithcal.au.calendarappexample.CalendarUtils.daysInMonthArray;
+import static codewithcal.au.calendarappexample.CalendarUtils.daysInWeekArray;
+import static codewithcal.au.calendarappexample.CalendarUtils.monthYearFromDate;
+
+public class WeekViewActivity extends AppCompatActivity implements CalendarAdapter.OnItemListener
+{
+ private TextView monthYearText;
+ private RecyclerView calendarRecyclerView;
+ private ListView eventListView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_week_view);
+ initWidgets();
+ setWeekView();
+ }
+
+ private void initWidgets()
+ {
+ calendarRecyclerView = findViewById(R.id.calendarRecyclerView);
+ monthYearText = findViewById(R.id.monthYearTV);
+ eventListView = findViewById(R.id.eventListView);
+ }
+
+ private void setWeekView()
+ {
+ monthYearText.setText(monthYearFromDate(CalendarUtils.selectedDate));
+ ArrayList days = daysInWeekArray(CalendarUtils.selectedDate);
+
+ CalendarAdapter calendarAdapter = new CalendarAdapter(days, this);
+ RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(), 7);
+ calendarRecyclerView.setLayoutManager(layoutManager);
+ calendarRecyclerView.setAdapter(calendarAdapter);
+ setEventAdpater();
+ }
+
+
+ public void previousWeekAction(View view)
+ {
+ CalendarUtils.selectedDate = CalendarUtils.selectedDate.minusWeeks(1);
+ setWeekView();
+ }
+
+ public void nextWeekAction(View view)
+ {
+ CalendarUtils.selectedDate = CalendarUtils.selectedDate.plusWeeks(1);
+ setWeekView();
+ }
+
+ @Override
+ public void onItemClick(int position, LocalDate date)
+ {
+ CalendarUtils.selectedDate = date;
+ setWeekView();
+ }
+
+ @Override
+ protected void onResume()
+ {
+ super.onResume();
+ setEventAdpater();
+ }
+
+ private void setEventAdpater()
+ {
+ ArrayList dailyEvents = Event.eventsForDate(CalendarUtils.selectedDate);
+ EventAdapter eventAdapter = new EventAdapter(getApplicationContext(), dailyEvents);
+ eventListView.setAdapter(eventAdapter);
+ }
+
+ public void newEventAction(View view)
+ {
+ startActivity(new Intent(this, EventEditActivity.class));
+ }
+
+ public void dailyAction(View view)
+ {
+ startActivity(new Intent(this, DailyCalendarActivity.class));
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_daily_calendar.xml b/app/src/main/res/layout/activity_daily_calendar.xml
new file mode 100644
index 0000000..dbc2b6b
--- /dev/null
+++ b/app/src/main/res/layout/activity_daily_calendar.xml
@@ -0,0 +1,78 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_event_edit.xml b/app/src/main/res/layout/activity_event_edit.xml
new file mode 100644
index 0000000..50ee1c7
--- /dev/null
+++ b/app/src/main/res/layout/activity_event_edit.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 67550fb..c3aad27 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -8,12 +8,25 @@
android:orientation="vertical"
tools:context=".MainActivity">
+
+
+
+