Skip to content

Commit

Permalink
Merge pull request #10 from adawoud/state-restoration-fix
Browse files Browse the repository at this point in the history
State restoration fix

Fix for issue#8, which can be found [here](https://github.com/adawoud/BottomSheetTimeRangePicker/issues)
  • Loading branch information
oheyadam committed Mar 21, 2019
2 parents aa12249 + 18f3e7f commit 3734724
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,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)
Expand All @@ -34,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
Expand Down Expand Up @@ -79,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,
Expand Down Expand Up @@ -140,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
}
Expand All @@ -150,7 +152,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() {
})
})
doActionIfValueIsNotNegative(startMinute, action = {
doActionBasedOnSdkLevel(
setInitialValuesBasedOnSdkLevel(
actionIfSdkLevelIsHigherThanOrEqualToM = {
startTimePicker.minute = startMinute
}
Expand All @@ -160,7 +162,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() {
})
})
doActionIfValueIsNotNegative(endHour, action = {
doActionBasedOnSdkLevel(
setInitialValuesBasedOnSdkLevel(
actionIfSdkLevelIsHigherThanOrEqualToM = {
endTimePicker.hour = endHour
}
Expand All @@ -171,9 +173,9 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() {

})
doActionIfValueIsNotNegative(endMinute, action = {
doActionBasedOnSdkLevel(
setInitialValuesBasedOnSdkLevel(
actionIfSdkLevelIsHigherThanOrEqualToM = {
endTimePicker.hour = endMinute
endTimePicker.hour = endHour
}
,
actionIfSdkLevelIsLowerThanM = {
Expand Down Expand Up @@ -224,7 +226,7 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() {
}
}

private fun doActionBasedOnSdkLevel(
private fun setInitialValuesBasedOnSdkLevel(
actionIfSdkLevelIsHigherThanOrEqualToM: () -> Unit,
actionIfSdkLevelIsLowerThanM: () -> Unit
) {
Expand Down Expand Up @@ -350,4 +352,5 @@ class BottomSheetTimeRangePicker : BottomSheetDialogFragment() {
return timeRangePicker
}
}

}
4 changes: 4 additions & 0 deletions bottomsheettimerangepicker/src/main/res/values/public.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<public />
</resources>
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ 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'
implementation 'com.android.support:design:28.0.0'
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")
}
2 changes: 1 addition & 1 deletion sample/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ class MainActivity : AppCompatActivity(), OnTimeRangeSelectedListener {
private fun String.prependZero(): String {
return "0".plus(this)
}

}

0 comments on commit 3734724

Please sign in to comment.