forked from tirth5828/US_2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monthly Calendar moved to Navigation Drawer
- Loading branch information
1 parent
82da9db
commit 17da59c
Showing
7 changed files
with
237 additions
and
205 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
app/src/main/java/com/example/us_2_0/MonthViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.example.us_2_0; | ||
|
||
import static com.example.us_2_0.CalendarUtils.daysInMonthArray; | ||
|
||
import androidx.annotation.RequiresApi; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.recyclerview.widget.GridLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
|
||
public class MonthViewActivity extends AppCompatActivity { | ||
private TextView monthYearText; | ||
private RecyclerView calendarRecyclerView; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_month_view); | ||
|
||
|
||
initWidgets(); | ||
CalendarUtils.selectedDate = LocalDate.now(); | ||
setMonthView(); | ||
|
||
} | ||
|
||
private void initWidgets() | ||
{ | ||
calendarRecyclerView = findViewById(R.id.calendarRecyclerView); | ||
monthYearText = findViewById(R.id.monthYearTV); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
private void setMonthView() | ||
{ | ||
monthYearText.setText(monthYearFromDate(CalendarUtils.selectedDate)); | ||
ArrayList<LocalDate> daysInMonth = daysInMonthArray(CalendarUtils.selectedDate); | ||
|
||
CalendarAdapter calendarAdapter = new CalendarAdapter(daysInMonth, this::onItemClick); | ||
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(), 7); | ||
calendarRecyclerView.setLayoutManager(layoutManager); | ||
calendarRecyclerView.setAdapter(calendarAdapter); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
private String monthYearFromDate(LocalDate date) | ||
{ | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy"); | ||
return date.format(formatter); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
public void previousMonthAction(View view) | ||
{ | ||
CalendarUtils.selectedDate = CalendarUtils.selectedDate.minusMonths(1); | ||
setMonthView(); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
public void nextMonthAction(View view) | ||
{ | ||
CalendarUtils.selectedDate = CalendarUtils.selectedDate.plusMonths(1); | ||
setMonthView(); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
public void onItemClick(int position, LocalDate date) | ||
{ | ||
if(date != null) | ||
{ | ||
CalendarUtils.selectedDate = date; | ||
setMonthView(); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.