Skip to content

Commit

Permalink
Single Date Selection added
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshwiselap committed Aug 21, 2019
1 parent e5dce55 commit aa0e389
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void dateSelectedIs(Date fromDate, Date toDate) {
text.setText(new SimpleDateFormat("dd-MMM-yyyy").format(fromDate)+" - "+new SimpleDateFormat("dd-MMM-yyyy").format(toDate));
}
});
rangeCalender.setSetSameDateAsFromDateIfToDateNotSelected(false);
rangeCalender.show();
}
});
Expand Down
21 changes: 15 additions & 6 deletions rangecalender/src/main/java/com/rangecalender/RangeCalender.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@
import com.rangecalender.interfaces.OnDateSelected;

import java.util.Date;

/***
* @author Palash Dumbare
* This will be the class which will be interacted by the client class
*
* **/
public class RangeCalender {
private Context context;
private OnDateSelected onDateSelected;
private int color = R.color.design_default_color_primary;
private boolean setSameDateAsFromDateIfToDateNotSelected = false;

public RangeCalender(Context context,OnDateSelected onDateSelected) {
this.context = context;
this.onDateSelected = onDateSelected;
}

public RangeCalender(Context context,int color,OnDateSelected onDateSelected) {
this.color = color;
this.context = context;
this.onDateSelected = onDateSelected;
}
/**
* @param b : if set true, todate selection will not be compulsary and blinking animation will not be there,
* todate will be same as fromDate.
* **/
public void setSetSameDateAsFromDateIfToDateNotSelected(boolean b){
this.setSameDateAsFromDateIfToDateNotSelected = b;
}

public void show(){
CalenderDialog calenderDialog = new CalenderDialog(context,color, new OnDateSelected() {

CalenderDialog calenderDialog = new CalenderDialog(context,color, setSameDateAsFromDateIfToDateNotSelected,new OnDateSelected() {
@Override
public void dateSelectedIs(Date fromDate, Date toDate) {
onDateSelected.dateSelectedIs(fromDate,toDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,24 @@ public class CalenderAdapter extends RecyclerView.Adapter<CalenderAdapter.ViewHo
private int color ;
private final String TAG = CalenderAdapter.class.getSimpleName();

public CalenderAdapter(ArrayList<MyCalender> calenders, CalenderDayClicked dayClickedListener) {
this.calenders = calenders;

public CalenderAdapter(CalenderDayClicked dayClickedListener) {
this.dayClickedListener = dayClickedListener;
int s = fixLocation(calenders.get(0));
for (int i = 0; i < s; i++) {
this.calenders.add(i, null);
}
}

public CalenderAdapter(ArrayList<MyCalender> calenders, CalenderDayClicked dayClickedListener,MyCalender fromDate,MyCalender toDate) {

public void setCalenders(ArrayList<MyCalender> calenders,MyCalender fromDate,MyCalender toDate) {
this.calenders = calenders;
this.fromDate = fromDate;
this.toDate = toDate;
this.dayClickedListener = dayClickedListener;
this.fromDate = fromDate;
int s = fixLocation(calenders.get(0));
for (int i = 0; i < s; i++) {
this.calenders.add(i, null);
}
}
notifyDataSetChanged();
}




public void setColor(int color){
Expand Down Expand Up @@ -127,22 +126,15 @@ public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
}
}

// if (toDateSelectedPosition != -1 && fromDateSelectedPosition != -1){
// if (toDateSelectedPosition != position && fromDateSelectedPosition!=position){
// if (position < toDateSelectedPosition && position >fromDateSelectedPosition){
//
// }
// }
// }


holder.rootLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (fromDate == null && toDate == null){
fromDateSelectedPosition = position;
fromDate = calenders.get(position);
Log.d(TAG,"IN CALENDER FIRST");
}else if(fromDate != null && toDate ==null){
}else if(fromDate != null && toDate ==null){
toDate = calenders.get(position);
try {
if (fromDate.getDate().after(toDate.getDate())) {
Expand All @@ -157,9 +149,7 @@ public void onClick(View v) {
e.printStackTrace();
}

Log.d(TAG,"IN CALENDER Second");
} else if(fromDate !=null && toDate!=null){
Log.d(TAG,"IN CALENDER THIRD");
} else if(fromDate !=null && toDate!=null){
fromDateSelectedPosition = position;
fromDate = calenders.get(position);
toDate = null;
Expand All @@ -177,8 +167,7 @@ public void onClick(View v) {


private void hightLightItem(ViewHolder holder,int position){
Log.d(TAG,"CHECKING FROMD DATE "+fromDateSelectedPosition +" "+toDateSelectedPosition);
if (fromDateSelectedPosition == position || toDateSelectedPosition == position){
if (fromDateSelectedPosition == position || toDateSelectedPosition == position){
holder.dateTxt.setBackgroundColor(ContextCompat.getColor(context,color));
holder.dateTxt.setTextColor(ContextCompat.getColor(context,android.R.color.white));
}else{
Expand Down
20 changes: 17 additions & 3 deletions rangecalender/src/main/res/layout/calender_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
<TextView
android:id="@+id/fromDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:text="From Date"
android:paddingLeft="10dp"
android:textColor="@android:color/white"
android:textSize="16dp"
android:layout_weight="1"
>
>

</TextView>

Expand All @@ -86,7 +86,7 @@
<TextView
android:id="@+id/toDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:text="To Date"
android:textColor="@android:color/white"
android:textSize="16dp"
Expand All @@ -100,11 +100,25 @@

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tabLine1"
android:layout_width="140dp"
android:layout_height="2dp"
android:background="@android:color/white"
android:layout_margin="0.25dp"/>
</LinearLayout>




</LinearLayout>




<android.support.v7.widget.CardView
android:id="@+id/yearPickerLayout"
android:layout_width="150dp"
Expand Down

0 comments on commit aa0e389

Please sign in to comment.