mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-09 19:10:51 +00:00
修复:未筛选时无法直接清空日志BUG #463
This commit is contained in:
parent
b80b1f9620
commit
40c8c5be6e
@ -27,9 +27,6 @@ interface MsgDao {
|
||||
@Query("DELETE FROM Msg where id=:id")
|
||||
fun delete(id: Long)
|
||||
|
||||
@Query("DELETE FROM Msg where type=:type")
|
||||
fun deleteAll(type: String): Completable
|
||||
|
||||
@RawQuery
|
||||
fun deleteAll(sql: SupportSQLiteQuery): Int
|
||||
|
||||
|
@ -14,8 +14,6 @@ class MsgRepository(private val msgDao: MsgDao) {
|
||||
|
||||
fun deleteAll() = msgDao.deleteAll()
|
||||
|
||||
fun deleteAll(type: String) = msgDao.deleteAll(type)
|
||||
|
||||
@WorkerThread
|
||||
fun deleteTimeAgo(time: Long) = msgDao.deleteTimeAgo(time)
|
||||
|
||||
|
@ -10,6 +10,7 @@ import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
import com.idormy.sms.forwarder.database.dao.MsgDao
|
||||
import com.idormy.sms.forwarder.database.entity.MsgAndLogs
|
||||
import com.idormy.sms.forwarder.database.ext.ioThread
|
||||
import com.idormy.sms.forwarder.utils.Log
|
||||
import com.xuexiang.xutil.data.DateUtils
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@ -55,18 +56,16 @@ class MsgViewModel(private val dao: MsgDao) : ViewModel() {
|
||||
}
|
||||
|
||||
fun deleteAll() = ioThread {
|
||||
if (filter.isEmpty()) {
|
||||
dao.deleteAll(type)
|
||||
} else {
|
||||
val sb = StringBuilder().apply {
|
||||
append("DELETE FROM Msg WHERE type = '$type'")
|
||||
val sb = StringBuilder().apply {
|
||||
append("DELETE FROM Msg WHERE type = '$type'")
|
||||
if (filter.isNotEmpty()) {
|
||||
append(getOtherCondition())
|
||||
}
|
||||
|
||||
//Log.d("MsgViewModel", "sql: $sb")
|
||||
val query = SimpleSQLiteQuery(sb.toString())
|
||||
dao.deleteAll(query)
|
||||
}
|
||||
|
||||
Log.d("MsgViewModel", "sql: $sb")
|
||||
val query = SimpleSQLiteQuery(sb.toString())
|
||||
dao.deleteAll(query)
|
||||
}
|
||||
|
||||
private fun getOtherCondition(): String {
|
||||
|
@ -85,6 +85,7 @@ class LogsFragment : BaseFragment<FragmentLogsBinding?>(), MsgPagingAdapter.OnIt
|
||||
.negativeText(R.string.lab_no)
|
||||
.onPositive { _: MaterialDialog?, _: DialogAction? ->
|
||||
try {
|
||||
Log.d(TAG, "deleteAll, currentType:$currentType, currentFilter:$currentFilter")
|
||||
viewModel.setType(currentType).setFilter(currentFilter).deleteAll()
|
||||
reloadData()
|
||||
XToastUtils.success(if (currentFilter.isEmpty()) R.string.delete_type_log_toast else R.string.delete_filter_log_toast)
|
||||
|
Loading…
Reference in New Issue
Block a user