Browse Source

Put redundant code in parent viewmodel

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
2fd9589aaf
  1. 10
      app/src/main/java/awais/instagrabber/fragments/main/viewmodels/BasePostViewModel.java
  2. 11
      app/src/main/java/awais/instagrabber/fragments/main/viewmodels/DiscoverItemViewModel.java
  3. 12
      app/src/main/java/awais/instagrabber/fragments/main/viewmodels/FeedViewModel.java
  4. 11
      app/src/main/java/awais/instagrabber/fragments/main/viewmodels/PostsViewModel.java

10
app/src/main/java/awais/instagrabber/fragments/main/viewmodels/BasePostViewModel.java

@ -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;
}
}

11
app/src/main/java/awais/instagrabber/fragments/main/viewmodels/DiscoverItemViewModel.java

@ -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;
}
}

12
app/src/main/java/awais/instagrabber/fragments/main/viewmodels/FeedViewModel.java

@ -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;
}
}

11
app/src/main/java/awais/instagrabber/fragments/main/viewmodels/PostsViewModel.java

@ -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;
}
}
Loading…
Cancel
Save