blob: b28fe6f2f5ad53e1af16dec6116c609424ca07f4 (
plain) (
blame)
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
|
package ml.docilealligator.infinityforreddit.recentsearchquery;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import java.util.List;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class RecentSearchQueryViewModel extends ViewModel {
private final LiveData<List<RecentSearchQuery>> mAllRecentSearchQueries;
public RecentSearchQueryViewModel(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
mAllRecentSearchQueries = new RecentSearchQueryRepository(redditDataRoomDatabase, username).getAllRecentSearchQueries();
}
public LiveData<List<RecentSearchQuery>> getAllRecentSearchQueries() {
return mAllRecentSearchQueries;
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private final RedditDataRoomDatabase mRedditDataRoomDatabase;
private final String mUsername;
public Factory(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
mUsername = username;
}
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
return (T) new RecentSearchQueryViewModel(mRedditDataRoomDatabase, mUsername);
}
}
}
|