Skip to content

Commit

Permalink
- Fix bug in reusability of calendar dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-sardari committed Jun 26, 2020
1 parent 0e0a2af commit fab8d14
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 693 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ allprojects {
Step 2. Add the dependency
```groovy
dependencies {
implementation 'com.github.ali-sardari:PersianRangeDatePicker:1.2.1'
implementation 'com.github.ali-sardari:PersianRangeDatePicker:1.3.0'
}
```

Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ dependencies {
implementation project(path: ':daterangepicker')
// implementation 'com.github.ali-sardari:PersianRangeDatePicker:1.1.3'
implementation 'com.android.support:appcompat-v7:28.0.0'

}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
Expand All @@ -14,6 +15,7 @@ public class MainActivity extends AppCompatActivity {

Button btn_ShowDatePicker;
TextView txtStartDate, txtEndDate;
DateRangeCalendarView calendar;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -24,14 +26,55 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void initSingleDate() {
calendar = findViewById(R.id.calendar);
btn_ShowDatePicker = findViewById(R.id.btn_ShowDatePicker);
txtStartDate = findViewById(R.id.txtStartDate);
txtEndDate = findViewById(R.id.txtEndDate);
//********************************************************

final DatePickerDialog datePickerDialog = new DatePickerDialog(this);
datePickerDialog.setSelectionMode(DateRangeCalendarView.SelectionMode.Range);
// datePickerDialog.setEnableTimePicker(true);
// datePickerDialog.setShowGregorianDate(true);
datePickerDialog.setTextSizeTitle(10.0f);
datePickerDialog.setTextSizeWeek(12.0f);
datePickerDialog.setTextSizeDate(14.0f);
datePickerDialog.setCanceledOnTouchOutside(true);
datePickerDialog.setOnRangeDateSelectedListener(new DatePickerDialog.OnRangeDateSelectedListener() {
@Override
public void onRangeDateSelected(PersianCalendar startDate, PersianCalendar endDate) {
txtStartDate.setText(startDate.getPersianShortDateTime());
txtEndDate.setText(endDate.getPersianShortDateTime());
}
});
// datePickerDialog.setAcceptButtonColor(ContextCompat.getColor(this, R.color.colorAccent));
// datePickerDialog.showDialog();
btn_ShowDatePicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowDatePicker();
datePickerDialog.showDialog();
}
});

//********************************************************


DateRangeCalendarView calendar = findViewById(R.id.calendar);
calendar.setCalendarListener(new DateRangeCalendarView.CalendarListener() {
@Override
public void onDateSelected(PersianCalendar date) {
Log.w("calendar",date.getPersianShortDate());
}

@Override
public void onDateRangeSelected(PersianCalendar startDate, PersianCalendar endDate) {
Log.w("calendar",startDate.getPersianShortDate());

}

@Override
public void onCancel() {

}
});
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@
android:layout_marginTop="50dp"
android:text="انتخاب تاریخ" />


<com.sardari.daterangepicker.customviews.DateRangeCalendarView
android:id="@+id/calendar"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_width="300dp"
android:layout_height="300dp"/>

</RelativeLayout>
28 changes: 13 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

ext.kotlin_version = '1.3.72'

repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }

}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
// classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.4.0'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand All @@ -31,13 +29,13 @@ task clean(type: Delete) {

ext {
configuration = [
appName : "MyRefah",
applicationId : "com.sardari.persianrangedatepicker",
compileSdkVersion: 29,
buildToolsVersion: "29.0.1",
minSdkVersion : 17,
targetSdkVersion : 29,
versionCode : 2,
versionName : "1.2.1",
appName : "MyRefah",
applicationId : "com.sardari.persianrangedatepicker",
compileSdkVersion : 29,
buildToolsVersion : "29.0.2",
minSdkVersion : 17,
targetSdkVersion : 29,
versionCode : 3,
versionName : "1.3.0",
]
}
3 changes: 0 additions & 3 deletions daterangepicker/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group = 'com.github.persianrangedatepicker'

def appConfig = rootProject.ext.configuration

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import java.util.Calendar;
import java.util.Locale;

import static com.sardari.daterangepicker.customviews.DateRangeCalendarView.SelectionMode.Range;
import static com.sardari.daterangepicker.customviews.DateRangeCalendarView.SelectionMode.Single;

public class DateRangeCalendarView extends LinearLayout {
//region Fields
private Context mContext;
Expand All @@ -54,6 +51,8 @@ public class DateRangeCalendarView extends LinearLayout {
private boolean shouldEnabledTime = false;
private float textSizeTitle, textSizeWeek, textSizeDate;
private PersianCalendar selectedCal, date;
private boolean isHideHeader = false;
public static String selectedDay = "";
//endregion

//region Enum
Expand Down Expand Up @@ -233,7 +232,7 @@ public void onClick(View view) {
date = DayContainer.GetDateFromKey(String.valueOf(key));
selectedCal.setPersianDate(date.getPersianYear(), date.getPersianMonth(), date.getPersianDay());

if (selectionMode == Single.getValue()) {
if (selectionMode == SelectionMode.Single.getValue()) {
//region SelectionMode.Single
resetAllSelectedViews();
makeAsSelectedDate(container, 0);
Expand Down Expand Up @@ -271,7 +270,7 @@ public void onCancel() {
//endregion
}
//endregion
} else if (selectionMode == Range.getValue()) {
} else if (selectionMode == SelectionMode.Range.getValue()) {
//region SelectionMode.Range
if (minSelectedDate != null) {
if (maxSelectedDate == null) {
Expand Down
Loading

0 comments on commit fab8d14

Please sign in to comment.