From b87136d0c69b882fd53e6b9ce63ef5b6c8bd95a4 Mon Sep 17 00:00:00 2001 From: adawoud Date: Thu, 21 Mar 2019 14:41:07 +0200 Subject: [PATCH 1/3] Fix a bug where the endHour value was set to endMinute in initInitialTimeValuesIfAdjusted() Issue: https://github.com/adawoud/BottomSheetTimeRangePicker/issues/8 --- .../bottomsheettimepicker/BottomSheetTimeRangePicker.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bottomsheettimerangepicker/src/main/java/me/adawoud/bottomsheettimepicker/BottomSheetTimeRangePicker.kt b/bottomsheettimerangepicker/src/main/java/me/adawoud/bottomsheettimepicker/BottomSheetTimeRangePicker.kt index 2cc4d78..a766004 100644 --- a/bottomsheettimerangepicker/src/main/java/me/adawoud/bottomsheettimepicker/BottomSheetTimeRangePicker.kt +++ b/bottomsheettimerangepicker/src/main/java/me/adawoud/bottomsheettimepicker/BottomSheetTimeRangePicker.kt @@ -10,7 +10,6 @@ import android.widget.TabHost import kotlinx.android.synthetic.main.time_range_picker.* import me.adawoud.bottomsheetpickers.R - @Suppress("DEPRECATION") // We deal with it below class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { private lateinit var listener: OnTimeRangeSelectedListener @@ -173,7 +172,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { doActionIfValueIsNotNegative(endMinute, action = { doActionBasedOnSdkLevel( actionIfSdkLevelIsHigherThanOrEqualToM = { - endTimePicker.hour = endMinute + endTimePicker.hour = endHour } , actionIfSdkLevelIsLowerThanM = { @@ -350,4 +349,5 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { return timeRangePicker } } + } \ No newline at end of file From e2a9c920afbb7d144a0e01fe5e685741c2494658 Mon Sep 17 00:00:00 2001 From: adawoud Date: Thu, 21 Mar 2019 14:42:54 +0200 Subject: [PATCH 2/3] Define an empty public.xml file so the library doesn't expose any of its internal resources --- bottomsheettimerangepicker/src/main/res/values/public.xml | 4 ++++ sample/build.gradle | 2 +- sample/proguard-rules.pro | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 bottomsheettimerangepicker/src/main/res/values/public.xml diff --git a/bottomsheettimerangepicker/src/main/res/values/public.xml b/bottomsheettimerangepicker/src/main/res/values/public.xml new file mode 100644 index 0000000..22d1406 --- /dev/null +++ b/bottomsheettimerangepicker/src/main/res/values/public.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 65e0797..8cfbf94 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -22,6 +22,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(":bottomsheettimerangepicker") implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' @@ -29,5 +30,4 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation project(":bottomsheettimerangepicker") } \ No newline at end of file diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro index f1b4245..481bb43 100644 --- a/sample/proguard-rules.pro +++ b/sample/proguard-rules.pro @@ -18,4 +18,4 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile +#-renamesourcefileattribute SourceFile \ No newline at end of file From 18f3e7f78da919a4cfd9c5bd982d6acfe9fa7a4a Mon Sep 17 00:00:00 2001 From: adawoud Date: Thu, 21 Mar 2019 14:53:10 +0200 Subject: [PATCH 3/3] Code cleanup --- .../BottomSheetTimeRangePicker.kt | 21 +++++++++++-------- .../bottomsheettimepicker/MainActivity.kt | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bottomsheettimerangepicker/src/main/java/me/adawoud/bottomsheettimepicker/BottomSheetTimeRangePicker.kt b/bottomsheettimerangepicker/src/main/java/me/adawoud/bottomsheettimepicker/BottomSheetTimeRangePicker.kt index a766004..ea33af8 100644 --- a/bottomsheettimerangepicker/src/main/java/me/adawoud/bottomsheettimepicker/BottomSheetTimeRangePicker.kt +++ b/bottomsheettimerangepicker/src/main/java/me/adawoud/bottomsheettimepicker/BottomSheetTimeRangePicker.kt @@ -22,8 +22,11 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { private var endHour = -1 private var endMinute = -1 - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = - LayoutInflater.from(context).inflate(R.layout.time_range_picker, container, false) + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? = LayoutInflater.from(context).inflate(R.layout.time_range_picker, container, false) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -33,7 +36,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { startMinute = bundle.getInt(KEY_START_MINUTE) endHour = bundle.getInt(KEY_END_HOUR) endMinute = bundle.getInt(KEY_END_MINUTE) - doActionBasedOnSdkLevel( + setInitialValuesBasedOnSdkLevel( actionIfSdkLevelIsHigherThanOrEqualToM = { startTimePicker.hour = startHour startTimePicker.minute = startMinute @@ -78,7 +81,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { btnSetTimeRange.setOnClickListener { // Pass these values to the calling Activity/Fragment if (::listener.isInitialized) { - doActionBasedOnSdkLevel( + setInitialValuesBasedOnSdkLevel( actionIfSdkLevelIsHigherThanOrEqualToM = { listener.onTimeRangeSelected( startTimePicker.hour, @@ -139,7 +142,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { // Set initial values if the user has changed them before initializing private fun initInitialTimeValuesIfAdjusted() { doActionIfValueIsNotNegative(startHour, action = { - doActionBasedOnSdkLevel( + setInitialValuesBasedOnSdkLevel( actionIfSdkLevelIsHigherThanOrEqualToM = { startTimePicker.hour = startHour } @@ -149,7 +152,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { }) }) doActionIfValueIsNotNegative(startMinute, action = { - doActionBasedOnSdkLevel( + setInitialValuesBasedOnSdkLevel( actionIfSdkLevelIsHigherThanOrEqualToM = { startTimePicker.minute = startMinute } @@ -159,7 +162,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { }) }) doActionIfValueIsNotNegative(endHour, action = { - doActionBasedOnSdkLevel( + setInitialValuesBasedOnSdkLevel( actionIfSdkLevelIsHigherThanOrEqualToM = { endTimePicker.hour = endHour } @@ -170,7 +173,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { }) doActionIfValueIsNotNegative(endMinute, action = { - doActionBasedOnSdkLevel( + setInitialValuesBasedOnSdkLevel( actionIfSdkLevelIsHigherThanOrEqualToM = { endTimePicker.hour = endHour } @@ -223,7 +226,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() { } } - private fun doActionBasedOnSdkLevel( + private fun setInitialValuesBasedOnSdkLevel( actionIfSdkLevelIsHigherThanOrEqualToM: () -> Unit, actionIfSdkLevelIsLowerThanM: () -> Unit ) { diff --git a/sample/src/main/java/me/adawoud/bottomsheettimepicker/MainActivity.kt b/sample/src/main/java/me/adawoud/bottomsheettimepicker/MainActivity.kt index 9a76969..e275cd4 100644 --- a/sample/src/main/java/me/adawoud/bottomsheettimepicker/MainActivity.kt +++ b/sample/src/main/java/me/adawoud/bottomsheettimepicker/MainActivity.kt @@ -47,4 +47,5 @@ class MainActivity : AppCompatActivity(), OnTimeRangeSelectedListener { private fun String.prependZero(): String { return "0".plus(this) } + } \ No newline at end of file