From 1a281d8354622a3606360f9f9a7fe4bb7d6a2c3a Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期日, 27 四月 2025 13:22:26 +0800
Subject: [PATCH] fix 短信
---
app/src/main/java/com/example/firstapp/ui/dashboard/DashboardViewModel.kt | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/app/src/main/java/com/example/firstapp/ui/dashboard/DashboardViewModel.kt b/app/src/main/java/com/example/firstapp/ui/dashboard/DashboardViewModel.kt
index e47a4a6..192b2ed 100644
--- a/app/src/main/java/com/example/firstapp/ui/dashboard/DashboardViewModel.kt
+++ b/app/src/main/java/com/example/firstapp/ui/dashboard/DashboardViewModel.kt
@@ -1,13 +1,56 @@
package com.example.firstapp.ui.dashboard
-import androidx.lifecycle.LiveData
-import androidx.lifecycle.MutableLiveData
-import androidx.lifecycle.ViewModel
+import android.app.Application
+import androidx.lifecycle.AndroidViewModel
+import androidx.lifecycle.asLiveData
+import androidx.lifecycle.viewModelScope
+import com.example.firstapp.AppDatabase
+import com.example.firstapp.database.entity.Code
+import com.example.firstapp.database.repository.CodeRepository
+import kotlinx.coroutines.launch
-class DashboardViewModel : ViewModel() {
+class DashboardViewModel(application: Application) : AndroidViewModel(application) {
- private val _text = MutableLiveData<String>().apply {
- value = "This is dashboard Fragment"
+ private val repository: CodeRepository
+
+ init {
+ val codeDao = AppDatabase.getInstance(application).codeDao()
+ repository = CodeRepository(codeDao)
}
- val text: LiveData<String> = _text
+
+ fun getPackages(date: Long, dateType: String) =
+ repository.getPackages(date, dateType).asLiveData()
+
+ fun getPackagesReaded(date: Long, dateType: String) =
+ repository.getPackagesReaded(date, dateType).asLiveData()
+
+ fun getCourierStats(date: Long, dateType: String) =
+ repository.getCourierStats(date, dateType).asLiveData()
+
+ fun getYearlyHeatmap(date: Long) = repository.getYearlyHeatmap(date).asLiveData()
+
+
+ fun getWeeklyStats(date: Long, weekCount: Int = 6) =
+ repository.getWeeklyStats(date, weekCount).asLiveData()
+
+ fun getMonthlyStats(date: Long) = repository.getMonthlyStats(date).asLiveData()
+
+ fun getYearlyStats(date: Long) = repository.getYearlyStats(date).asLiveData()
+
+ fun getYearMonthlyStats(date: Long) =
+ repository.getYearMonthlyStats(date).asLiveData()
+
+ fun insert(code: Code) = viewModelScope.launch {
+ repository.insert(code)
+ }
+
+ fun getCurrentWeekStats(date: Long) =
+ repository.getCurrentWeekStats(date).asLiveData()
+
+ fun getCurrentYearStats(date: Long) =
+ repository.getCurrentYearStats(date).asLiveData()
+
+ fun getCurrentWeekStats2(startDateCur: String, endDateCur: String) = repository.getCurrentWeekStats2(startDateCur,endDateCur).asLiveData()
+ fun getWeeklyStatsChart(startDateCur: String, endDateCur: String) = repository.getWeeklyStatsChart(startDateCur, endDateCur).asLiveData()
+ fun getCurrentDayStatsByType(startDateCur: String, endDateCur: String,type: String) =repository.getDateStatsByType(startDateCur, endDateCur,type).asLiveData()
}
\ No newline at end of file
--
Gitblit v1.9.3