tj
2025-04-07 3433f3e9a0254b24cec2836b112267b1af3f9101
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.example.firstapp.ui.dashboard
 
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import androidx.room.RewriteQueriesToDropUnusedColumns
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(application: Application) : AndroidViewModel(application) {
 
    private val repository: CodeRepository
 
    init {
        val codeDao = AppDatabase.getInstance(application).codeDao()
        repository = CodeRepository(codeDao)
    }
 
    fun getPackages(date: Long, dateType: String) =
        repository.getPackages(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()
}