Commit 66bbc4e8 authored by 赵鹏翔's avatar 赵鹏翔

优化时间选择器逻辑

parent 0b414329
......@@ -2,6 +2,7 @@ package com.miya.fastcashier.ui
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
......@@ -21,6 +22,7 @@ import com.miya.fastcashier.utils.*
import com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import com.miya.fastcashier.viewmodel.MainViewModel
import es.dmoral.toasty.Toasty
import java.util.*
class MainActivity : BaseActivity() {
......@@ -78,10 +80,15 @@ class MainActivity : BaseActivity() {
}
binding.llStatistic.clickWithTrigger {
if (dateSelectHelper == null) {
dateSelectHelper = DateSelectHelper(this@MainActivity) {
viewModel.orderStatistics(it, Date(), false)
dateSelectHelper = DateSelectHelper(this@MainActivity) {
var currentDate = Date()
if (currentDate.time <= it.time){
CenterToasty.error(this@MainActivity,getString(R.string.toast_warn_time)).show()
return@DateSelectHelper
}
viewModel.orderStatistics(it, currentDate, false)
}
dateSelectHelper!!.showDatePicker()
}
......@@ -130,7 +137,7 @@ class MainActivity : BaseActivity() {
})
}
private fun showConfirmBalanceDialog(){
private fun showConfirmBalanceDialog() {
if (confirmDialog == null || !confirmDialog!!.isShowing) {
confirmDialog = CommonDialog(this)
confirmDialog!!.setCustomMessage(getString(R.string.app_text_confirm_balance))
......@@ -153,7 +160,7 @@ class MainActivity : BaseActivity() {
}
}
private fun toBalance(){
private fun toBalance() {
//上次记录的时间,或者当天0点
var timeMillis = LocalKeyDataMKManageKit.getBalanceDate()
if (timeMillis > 0L && timeMillis <= System.currentTimeMillis()) {
......
......@@ -15,21 +15,6 @@ import java.util.*
class DateSelectHelper(val act: Activity, val callback: (Date) -> Unit) {
var timePickerView: TimePickerView? = null
fun showDatePicker() {
if (timePickerView == null) {
initTimePicker()
}
val date = Calendar.getInstance()
date.set(
date.get(Calendar.YEAR),
date.get(Calendar.MONTH),
date.get(Calendar.DAY_OF_MONTH),
0,
0
)
timePickerView!!.setDate(date)
timePickerView!!.show()
}
private fun initTimePicker() {
val calendar = Calendar.getInstance()
......@@ -51,9 +36,9 @@ class DateSelectHelper(val act: Activity, val callback: (Date) -> Unit) {
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE)
)
timePickerView = TimePickerBuilder(act, OnTimeSelectListener { date, v ->
timePickerView = TimePickerBuilder(act) { date, v ->
callback(date)
})
}
.setTitleText("请选择开始时间")
.setType(booleanArrayOf(false, false, false, true, true, false))
.setDate(startDate)
......@@ -67,9 +52,22 @@ class DateSelectHelper(val act: Activity, val callback: (Date) -> Unit) {
.build()
}
fun showDatePicker() {
timePickerView = null
initTimePicker()
val date = Calendar.getInstance()
date.set(
date.get(Calendar.YEAR),
date.get(Calendar.MONTH),
date.get(Calendar.DAY_OF_MONTH),
0,
0
)
timePickerView!!.setDate(date)
timePickerView!!.show()
}
fun dismiss() {
timePickerView?.dismiss()
}
}
\ No newline at end of file
......@@ -38,6 +38,8 @@
<string name="app_confirm">确认</string>
<string name="app_unkown">未知</string>
<string name="toast_click_again">再点击%1$d次进入身份验证</string>
<string name="toast_warn_time">开始时间不能大于结束时间!</string>
<!--日志上传字段-->
<string name="lfile_Cancel">取消全选</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment