| | |
| | | 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.model.PackageInfo |
| | | import com.example.firstapp.repository.PackageRepository |
| | | 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: PackageRepository |
| | | |
| | | |
| | | private val repository: CodeRepository |
| | | |
| | | init { |
| | | val packageDao = AppDatabase.getInstance(application).packageDao() |
| | | repository = PackageRepository(packageDao) |
| | | val codeDao = AppDatabase.getInstance(application).codeDao() |
| | | repository = CodeRepository(codeDao) |
| | | } |
| | | |
| | | fun getPackages(date: Long, dateType: String) = |
| | | |
| | | fun getPackages(date: Long, dateType: String) = |
| | | repository.getPackages(date, dateType).asLiveData() |
| | | |
| | | fun getCourierStats(date: Long) = repository.getCourierStats(date).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 getDailyStats(date: Long) = repository.getDailyStats(date).asLiveData() |
| | | fun getMonthlyStats(date: Long) = repository.getMonthlyStats(date).asLiveData() |
| | | |
| | | fun getYearlyStats(date: Long) = repository.getYearlyStats(date).asLiveData() |
| | | |
| | | fun updatePackageStatus(packageInfo: PackageInfo) = viewModelScope.launch { |
| | | repository.update(packageInfo) |
| | | fun getYearMonthlyStats(date: Long) = |
| | | repository.getYearMonthlyStats(date).asLiveData() |
| | | |
| | | fun insert(code: Code) = viewModelScope.launch { |
| | | repository.insert(code) |
| | | } |
| | | |
| | | fun insert(packageInfo: PackageInfo) = viewModelScope.launch { |
| | | repository.insert(packageInfo) |
| | | } |
| | | fun getCurrentWeekStats(date: Long) = |
| | | repository.getCurrentWeekStats(date).asLiveData() |
| | | |
| | | fun getCurrentYearStats(date: Long) = |
| | | repository.getCurrentYearStats(date).asLiveData() |
| | | } |