Put redundant code in parent viewmodel

This commit is contained in:
Ammar Githam 2020-09-03 18:49:41 +09:00
parent daa5a110f2
commit 2fd9589aaf
4 changed files with 10 additions and 34 deletions

View File

@ -1,9 +1,19 @@
package awais.instagrabber.fragments.main.viewmodels;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import java.util.List;
import awais.instagrabber.models.BasePostModel;
public class BasePostViewModel<T extends BasePostModel> extends ViewModel {
private MutableLiveData<List<T>> list;
public MutableLiveData<List<T>> getList() {
if (list == null) {
list = new MutableLiveData<>();
}
return list;
}
}

View File

@ -1,18 +1,7 @@
package awais.instagrabber.fragments.main.viewmodels;
import androidx.lifecycle.MutableLiveData;
import java.util.List;
import awais.instagrabber.models.DiscoverItemModel;
public class DiscoverItemViewModel extends BasePostViewModel<DiscoverItemModel> {
private MutableLiveData<List<DiscoverItemModel>> list;
public MutableLiveData<List<DiscoverItemModel>> getList() {
if (list == null) {
list = new MutableLiveData<>();
}
return list;
}
}

View File

@ -1,19 +1,7 @@
package awais.instagrabber.fragments.main.viewmodels;
import androidx.lifecycle.MutableLiveData;
import java.util.Collections;
import java.util.List;
import awais.instagrabber.models.FeedModel;
public class FeedViewModel extends BasePostViewModel<FeedModel> {
private MutableLiveData<List<FeedModel>> list;
public MutableLiveData<List<FeedModel>> getList() {
if (list == null) {
list = new MutableLiveData<>(Collections.emptyList());
}
return list;
}
}

View File

@ -1,18 +1,7 @@
package awais.instagrabber.fragments.main.viewmodels;
import androidx.lifecycle.MutableLiveData;
import java.util.List;
import awais.instagrabber.models.PostModel;
public class PostsViewModel extends BasePostViewModel<PostModel> {
private MutableLiveData<List<PostModel>> list;
public MutableLiveData<List<PostModel>> getList() {
if (list == null) {
list = new MutableLiveData<>();
}
return list;
}
}