Skip to content

oOJohn6Oo/JWheelPicker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSinglePickerDialogFragment JMultiplePickerDialogFragment

Implementation

  • add repo maven { url 'https://jitpack.io' }
  • latest version LatestVersion
  • add implementation("com.github.oOJohn6Oo:JWheelPicker:<version>")

Usage

For Any Compose View Use

JWheelPicker(
modifier = modifier,
onSelectedItemChanged = onSelectedItemChanged,
textStyle = TextStyle(color = MaterialTheme.colors.onBackground, fontSize = 20.sp),
selectedTextColor = requiredData.getDesireSelectTextColor(LocalContext.current),
drawOverLay = rememberDefaultOverlayStyle(requiredData.overlayStyle),
initialIndex = requiredData.getSafeInitialIndex(),
itemCount = requiredData.dataList.size,
itemData = { index ->
requiredData.dataList[index]
},
)

JMultiWheelPicker(
modifier = modifier,
wheelCount = adapter.wheelCount,
generateJWheelPickerInfo = generateJWheelPickerInfo,
drawOverLay = rememberDefaultOverlayStyle(requiredData.overlayStyle),
key = key,
onSelectedItemChanged = onSelectedItemChanged,
selectedTextColor = requiredData.getDesireSelectTextColor(LocalContext.current),
)

JDateWheelPicker(
modifier = modifier,
datePickerMode = requiredData.datePickerMode,
timePickerMode = requiredData.timePickerMode,
containerHorizontalPadding = requiredData.containerHorizontalPaddingInDp.dp,
startLocalDateTime = requiredData.startLocalDateTime,
endLocalDateTime = requiredData.endLocalDateTime,
initialSelectDateTime = requiredData.initialSelectDateTime,
drawOverLay = rememberDefaultOverlayStyle(requiredData.overlayStyle),
onSelectedTimeChanged = onSelectedTimeChanged,
selectedTextColor = requiredData.getDesireSelectTextColor(LocalContext.current),
)

For Default BottomSheet Dialog Use

supportFragmentManager,
requiredData = JSinglePickerDialogAdapterData(
title = 0 to "SingleAdapterPicker",
overlayStyle = JWheelPickerHelper.OVERLAY_STYLE_RECTANGLE,
selectTextColorResId = android.R.color.holo_blue_dark,
adapterClass = TestMultipleJPickerAdapter::class.java,
adapterParamsAsBundle = Bundle().apply {
putInt("wheelCount", 1)
putIntArray("initialIndexes", intArrayOf(9))
},
),
)
} else {
JSinglePickerDialogFragment.show(
supportFragmentManager,
requiredData = JSinglePickerDialogData(
title = 0 to "SinglePicker",
initialIndex = 20,
dataList = (0..30).map { JWheelPickerItemInfo(it.toString(), it, "item$it") },
overlayStyle = JWheelPickerHelper.OVERLAY_STYLE_RECTANGLE
),
)
}
}

JMultiplePickerDialogFragment.show(
supportFragmentManager,
requiredData = JMultiPickerDialogData(
title = 0 to "MultiplePicker",
overlayStyle = JWheelPickerHelper.OVERLAY_STYLE_LINE,
adapterClass = TestMultipleJPickerAdapter::class.java,
),
)

JDateWheelPickerDialogFragment.show(
supportFragmentManager,
requiredData = JDatePickerDialogData(
title = 0 to "DatePicker",
overlayStyle = JWheelPickerHelper.OVERLAY_STYLE_RECTANGLE,
containerHorizontalPaddingInDp = 16
),
)

And using FragmentResult API to get the callback

supportFragmentManager.setFragmentResultListener(JSinglePickerDialogFragment.TAG, this) { tag, bundle ->
val isDismiss = bundle.getBoolean("dismiss", false)
if(isDismiss){
return@setFragmentResultListener
}
val result = bundle.getParcelableCompat(fragmentResultKey, JWheelPickerItemInfo::class.java)
Toast.makeText(this, result?.id.toString(), Toast.LENGTH_SHORT).show()
}