Skip to content

Commit

Permalink
Default Date Selection method added
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshwiselap committed Aug 22, 2019
1 parent 832c50b commit f85fc12
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ android {
dependencies {

def supportVersion = "28.0.0"

def constraintLayoutVersion = "1.1.0"


Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/wiselap/rangecalender/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import com.rangecalender.interfaces.OnDateSelected;
import com.rangecalender.RangeCalender;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


Expand All @@ -31,7 +31,7 @@ public void dateSelectedIs(Date fromDate, Date toDate) {
}
});
rangeCalender.setSetSameDateAsFromDateIfToDateNotSelected(false);
rangeCalender.show();
rangeCalender.show();
}
});

Expand Down
44 changes: 41 additions & 3 deletions rangecalender/src/main/java/com/rangecalender/CalenderDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class CalenderDialog extends Dialog implements CalenderDayClicked, View.O
private Animation anim;
private int color,width;
private boolean setSameDateAsFromDateIfToDateNotSelected;
private Date fromDate,toDate;
private final String TAG = CalenderDialog.class.getSimpleName();


Expand All @@ -72,10 +73,36 @@ public CalenderDialog(Context context, int color, boolean setSameDateAsFromDateI
show();
}

public CalenderDialog(Context context, int color,Date fromDate,Date toDate ,boolean setSameDateAsFromDateIfToDateNotSelected, OnDateSelected onDateSelected) {
super(context,android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth);
this.context = context;
this.onDateSelected = onDateSelected;
this.color = color;
this.fromDate = fromDate;
this.toDate = toDate;


this.setSameDateAsFromDateIfToDateNotSelected = setSameDateAsFromDateIfToDateNotSelected;
setContentView(R.layout.calender_dialog);
init();
events();
setUpCalender();
setOnUI();
generateCalender();
show();
}

private void setUpCalender() {
calendar = Calendar.getInstance();
month = calendar.get(Calendar.MONTH)+1;
year = calendar.get(Calendar.YEAR);
/**
* if fromDate is to be selected bydefault we will set it to calender
* */
if (fromDate!=null){
calendar.setTime(fromDate);
}

month = calendar.get(Calendar.MONTH) + 1;
year = calendar.get(Calendar.YEAR);

yearAdapter = new YearAdapter(years, String.valueOf(year),this);
yearList.setAdapter(yearAdapter);
Expand Down Expand Up @@ -162,7 +189,16 @@ private void generateCalender(){
}else {
calenderAdapter = new CalenderAdapter(this);
calenderAdapter.setColor(color);
calenderAdapter.setCalenders(Date_Utils.getDaysBetweenDates(fromDate, toDate),null,null);
if (fromDate!=null && toDate!=null) {
MyCalender fromDateCal = new MyCalender(fromDate.getDay(), fromDate.getMonth(), fromDate.getYear(), "");
MyCalender toDateCal = new MyCalender(toDate.getDay(),toDate.getMonth(),toDate.getYear(),"");
calenderAdapter.setCalenders(Date_Utils.getDaysBetweenDates(fromDate, toDate),fromDateCal,toDateCal);
}else if(fromDate!=null && toDate == null){
MyCalender fromDateCal = new MyCalender(fromDate.getDay(), fromDate.getMonth(), fromDate.getYear(), "");
calenderAdapter.setCalenders(Date_Utils.getDaysBetweenDates(fromDate, toDate),fromDateCal,null);
}else{
calenderAdapter.setCalenders(Date_Utils.getDaysBetweenDates(fromDate, toDate),null,null);
}
dateList.setAdapter(calenderAdapter);
}
}catch (Exception e){
Expand Down Expand Up @@ -275,4 +311,6 @@ private void setOnUI(){
monthYear.setText(new DateFormatSymbols().getMonths()[month-1]+" "+year);
generateCalender();
}


}
35 changes: 25 additions & 10 deletions rangecalender/src/main/java/com/rangecalender/RangeCalender.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class RangeCalender {
private OnDateSelected onDateSelected;
private int color = R.color.design_default_color_primary;
private boolean setSameDateAsFromDateIfToDateNotSelected = false;


private Date fromDate,toDate;
public RangeCalender(Context context,int color,OnDateSelected onDateSelected) {
this.color = color;
this.context = context;
Expand All @@ -30,15 +29,31 @@ public void setSetSameDateAsFromDateIfToDateNotSelected(boolean b){
this.setSameDateAsFromDateIfToDateNotSelected = b;
}

public void show(){
public void setDefaultDateSelection(Date fromDate,Date toDate){
this.fromDate = fromDate;
this.toDate = toDate;
}

CalenderDialog calenderDialog = new CalenderDialog(context,color, setSameDateAsFromDateIfToDateNotSelected,new OnDateSelected() {
@Override
public void dateSelectedIs(Date fromDate, Date toDate) {
onDateSelected.dateSelectedIs(fromDate,toDate);
}
});
calenderDialog.show();


public void show(){
CalenderDialog calenderDialog;
if (fromDate!=null){
calenderDialog = new CalenderDialog(context, color, fromDate, toDate, setSameDateAsFromDateIfToDateNotSelected, new OnDateSelected() {
@Override
public void dateSelectedIs(Date fromDate, Date toDate) {
onDateSelected.dateSelectedIs(fromDate, toDate);
}
});
}else {
calenderDialog = new CalenderDialog(context, color, setSameDateAsFromDateIfToDateNotSelected, new OnDateSelected() {
@Override
public void dateSelectedIs(Date fromDate, Date toDate) {
onDateSelected.dateSelectedIs(fromDate, toDate);
}
});
}
calenderDialog.show();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ public ViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {



if (calenders.get(position) == null){
holder.rootLayout.setVisibility(View.GONE);
} else{
Expand Down

0 comments on commit f85fc12

Please sign in to comment.