Not to hold a database instance in a viewmodel class

This commit is contained in:
Shinokuni 2019-02-23 21:46:21 +00:00
parent 3cee4fead6
commit 83ca13249a
1 changed files with 4 additions and 3 deletions

View File

@ -6,19 +6,20 @@ import android.arch.lifecycle.LiveData;
import android.support.annotation.NonNull;
import com.readrops.app.database.Database;
import com.readrops.app.database.dao.ItemDao;
import com.readrops.app.database.pojo.ItemWithFeed;
public class ItemViewModel extends AndroidViewModel {
private Database db;
private ItemDao itemDao;
public ItemViewModel(@NonNull Application application) {
super(application);
db = Database.getInstance(application);
itemDao = Database.getInstance(application).itemDao();
}
public LiveData<ItemWithFeed> getItemById(int id) {
return db.itemDao().getItemById(id);
return itemDao.getItemById(id);
}