Skip to content

Commit

Permalink
fix #57
Browse files Browse the repository at this point in the history
  • Loading branch information
loper7 committed Apr 24, 2022
1 parent 8a9ba34 commit 55c95d1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ dependencies {
//material
implementation 'com.google.android.material:material:1.2.4'

implementation 'com.github.loperSeven:DateTimePicker:0.5.7'
// implementation project(path: ':date_time_picker')
// implementation 'com.github.loperSeven:DateTimePicker:0.5.7'
implementation project(path: ':date_time_picker')

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/loper7/datepicker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class MainActivity : AppCompatActivity() {
picker.setOnDateTimeChangedListener{
var calendar = Calendar.getInstance()
calendar.timeInMillis = it
var lunar = Lunar.getInstance(calendar)
lunar?.apply {
Log.e("lunar",lunar.toString()+";maxDay->${getMaxDayInMonth()}")
}
}

btnCardDialog.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import java.util.*
* @Author: LOPER7
* @Email: [email protected]
*/
class CardDatePickerDialog(context: Context) : BottomSheetDialog(context,R.style.DateTimePicker_BottomSheetDialog), View.OnClickListener {
class CardDatePickerDialog(context: Context) :
BottomSheetDialog(context, R.style.DateTimePicker_BottomSheetDialog), View.OnClickListener {
companion object {
const val CARD = 0 //卡片
const val CUBE = 1 //方形
Expand Down Expand Up @@ -91,7 +92,7 @@ class CardDatePickerDialog(context: Context) : BottomSheetDialog(context,R.style
mBehavior = BottomSheetBehavior.from(bottomSheet)

//滑动关闭
mBehavior?.isHideable = builder?.touchHideable?:true
mBehavior?.isHideable = builder?.touchHideable ?: true

//背景模式
if (builder!!.model != 0) {
Expand Down Expand Up @@ -208,7 +209,7 @@ class CardDatePickerDialog(context: Context) : BottomSheetDialog(context,R.style
builder!!.wrapSelectorWheel
)

datePicker!!.setTextSize(13,15)
datePicker!!.setTextSize(13, 15)
if (builder!!.themeColor != 0) {
datePicker!!.setThemeColor(builder!!.themeColor)
tv_submit!!.setTextColor(builder!!.themeColor)
Expand All @@ -228,8 +229,15 @@ class CardDatePickerDialog(context: Context) : BottomSheetDialog(context,R.style
var calendar = Calendar.getInstance()
calendar.clear()
calendar.timeInMillis = millisecond
Lunar.getInstance(calendar)?.apply {
var str = "<font color='#999999'>农历</font>&nbsp;&nbsp;&nbsp;<font color='#333333'>$yearName $monthName $dayName<font/>&nbsp;&nbsp;&nbsp;<font color='#999999'>${StringUtils.getWeek(millisecond)}</font>"
Lunar.getInstance(calendar).apply {
var str = if (this == null)
"<font color='#999999'>暂无农历信息</font>"
else
"<font color='#999999'>农历</font>&nbsp;&nbsp;&nbsp;<font color='#333333'>$yearName $monthName $dayName<font/>&nbsp;&nbsp;&nbsp;<font color='#999999'>${
StringUtils.getWeek(
millisecond
)
}</font>"
tv_choose_date?.text = Html.fromHtml(str)
}
}
Expand Down Expand Up @@ -305,7 +313,7 @@ class CardDatePickerDialog(context: Context) : BottomSheetDialog(context,R.style
var wrapSelectorWheelTypes: MutableList<Int>? = mutableListOf()

@JvmField
var touchHideable:Boolean = true
var touchHideable: Boolean = true

@JvmField
var onChooseListener: ((Long) -> Unit)? = null
Expand Down Expand Up @@ -527,7 +535,7 @@ class CardDatePickerDialog(context: Context) : BottomSheetDialog(context,R.style
* 是否可以滑动关闭弹窗
* @param touchHideable 默认为 true
*/
fun setTouchHideable(touchHideable:Boolean = true):Builder{
fun setTouchHideable(touchHideable: Boolean = true): Builder {
this.touchHideable = touchHideable
return this
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.loper7.date_time_picker.utils.lunar

import android.util.Log
import com.loper7.date_time_picker.ext.getMaxDayAtYear
import com.loper7.date_time_picker.utils.lunar.LunarConstants.LUNAR_DAY_NAMES
import com.loper7.date_time_picker.utils.lunar.LunarConstants.LUNAR_DZ
Expand Down Expand Up @@ -100,21 +101,25 @@ class Lunar(
* @param calendar
* @return
*/
@Synchronized
fun hasLunarInfo(calendar: Calendar): Boolean {
val syear = calendar[Calendar.YEAR]
val dayoffset = calendar[Calendar.DAY_OF_YEAR] - 1
val lindex = syear - MIN_LUNAR_YEAR
if (lindex < 0 || lindex > LUNAR_TABLE.size) {
return false
}
var lyear = syear
val hexValue = LUNAR_TABLE[lindex]
val ldayoffset = hexValue and 0xFF
if (ldayoffset > dayoffset) {
lyear--
return try {
val syear = calendar[Calendar.YEAR]
val dayoffset = calendar[Calendar.DAY_OF_YEAR] - 1
val lindex = syear - MIN_LUNAR_YEAR
if (lindex < 0 || lindex >= LUNAR_TABLE.size) {
return false
}
var lyear = syear
val hexValue = LUNAR_TABLE[lindex]
val ldayoffset = hexValue and 0xFF
if (ldayoffset > dayoffset) {
lyear--
}
lyear >= MIN_LUNAR_YEAR
} catch (e: Throwable) {
e.printStackTrace()
false
}
return lyear >= MIN_LUNAR_YEAR
}
}

Expand Down

0 comments on commit 55c95d1

Please sign in to comment.