Commit b78e096b authored by wanglei's avatar wanglei

...

parent 73d13962
......@@ -56,18 +56,45 @@ class HistoryViewModel() : ViewModel() {
}
fun removeBean(bean: ScanBean) {
val scanBean = when (bean.scanType) {
FunctionUIBean.KEY_WIFI -> bean as WifiUIBean
FunctionUIBean.KEY_TEXT -> bean as TextUIBean
FunctionUIBean.KEY_EMAIL -> bean as EmailUIBean
else -> bean
when (bean.scanType) {
FunctionUIBean.KEY_WIFI -> {
SpJsonUtils.removeJsonBean<WifiUIBean>(bean.scanType, bean as WifiUIBean, removeIf = { it1, it2 ->
it1.createTime == it2.createTime
})
}
SpJsonUtils.removeJsonBean(bean.scanType, scanBean, removeIf = { it1, it2 ->
FunctionUIBean.KEY_TEXT -> {
SpJsonUtils.removeJsonBean<TextUIBean>(bean.scanType, bean as TextUIBean, removeIf = { it1, it2 ->
it1.createTime == it2.createTime
})
}
FunctionUIBean.KEY_EMAIL -> {
SpJsonUtils.removeJsonBean<EmailUIBean>(bean.scanType, bean as EmailUIBean, removeIf = { it1, it2 ->
it1.createTime == it2.createTime
})
}
FunctionUIBean.KEY_CONTACT -> {
}
FunctionUIBean.KEY_WEBSITE -> {
SpJsonUtils.removeJsonBean<WebsiteUIBean>(bean.scanType, bean as WebsiteUIBean, removeIf = { it1, it2 ->
it1.createTime == it2.createTime
})
}
FunctionUIBean.KEY_PRODUCT -> {
SpJsonUtils.removeJsonBean<ProductUIBean>(bean.scanType, bean as ProductUIBean, removeIf = { it1, it2 ->
it1.createTime == it2.createTime
})
}
}
historyList.removeIf { it.createTime == bean.createTime }
historyList.remove(bean)
}
......
......@@ -33,6 +33,9 @@ object SpJsonUtils {
saveJsonBeanList(key, arrayList.toList())
}
/**
* 这里保存一定要找到具体的类型,不能用父类
*/
inline fun <reified T> removeJsonBean(key: String, bean: T, crossinline removeIf: (it1: T, it2: T) -> Boolean) {
val list = getSpJsonList<T>(key).toMutableList()
list.removeIf { removeIf(it, bean) }
......
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