Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Widget
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Android Widget
Widget
Commits
fd7760d1
Commit
fd7760d1
authored
Sep 29, 2024
by
chuxiaoshan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化0到负数临界情况发送与判断。
parent
98d58d49
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
7 deletions
+27
-7
gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
+1
-1
build.gradle
zqtoolkit/build.gradle
+1
-1
ScaleBaseKit.kt
...c/main/java/com/qmai/zqtoolkit/base/scale/ScaleBaseKit.kt
+25
-5
No files found.
gradle/wrapper/gradle-wrapper.properties
View file @
fd7760d1
...
...
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
6.7-all
.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
7.4-bin
.zip
zqtoolkit/build.gradle
View file @
fd7760d1
...
...
@@ -30,7 +30,7 @@ android {
}
}
group
'com.qmai.android.zqtoolkit'
version
'1.3.9.
6
'
version
'1.3.9.
7
'
gradlePublish
{
...
...
zqtoolkit/src/main/java/com/qmai/zqtoolkit/base/scale/ScaleBaseKit.kt
View file @
fd7760d1
...
...
@@ -72,14 +72,33 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
}
}
private
fun
String
?.
toDoubleOrZero
():
Double
{
return
try
{
this
?.
toDouble
()
?:
0.0
}
catch
(
e
:
Exception
)
{
0.0
}
}
private
var
lastLivingWeight
:
LivingWeight
?
=
null
/**
* 判断是否需要立即发送
*/
private
fun
shouldEmitOnce
(
weight
:
LivingWeight
):
Boolean
{
val
lastNum
=
lastLivingWeight
?.
weight
.
toDoubleOrZero
()
val
num
=
weight
.
weight
.
toDoubleOrZero
()
return
(
lastNum
>=
0
&&
num
<
0.0
)
||
(
lastNum
<=
0
&&
num
>
0
)
}
override
fun
updateWeight
(
weight
:
LivingWeight
)
{
GlobalScope
.
launch
{
//稳定状态且读数正常
if
(
weight
.
isStable
&&
!
weight
.
isReadErr
)
{
if
(
weight
.
isStable
&&
!
weight
.
isReadErr
&&
!
shouldEmitOnce
(
weight
)
)
{
readErrCache
.
clear
()
when
{
stableWeight
.
size
==
STABLE_COUNT
->
{
va
r
single
=
stableWeight
.
distinctBy
{
it
.
weight
}
va
l
single
=
stableWeight
.
distinctBy
{
it
.
weight
}
if
(
single
.
size
==
1
)
{
//给业务的unit要小写
if
(
weight
.
unit
.
isNotEmpty
())
...
...
@@ -90,9 +109,8 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
}
stableWeight
.
clear
()
}
stableWeight
.
size
>
STABLE_COUNT
->
{
stableWeight
.
clear
()
}
stableWeight
.
size
>
STABLE_COUNT
->
stableWeight
.
clear
()
else
->
stableWeight
.
add
(
weight
)
}
}
else
{
...
...
@@ -104,9 +122,11 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
disconnect
()
connectCache
.
clear
()
}
else
->
readErrCache
.
add
(
true
)
}
}
lastLivingWeight
=
weight
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment