Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
refactor: Remove unnecessary transformations (#2444)
Browse files Browse the repository at this point in the history
  • Loading branch information
simarsingh24 authored and iamareebjamal committed May 12, 2018
1 parent 1e9e0dd commit 1f2ca18
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AboutFragmentViewModel extends ViewModel {
private FilterableRealmLiveData<Session> filterableRealmLiveData;
private List<String> dateList;
private LiveData<Event> eventLiveData;
private LiveData<List<Speaker>> featuredSpeakers;
private LiveRealmData<Speaker> featuredSpeakersLiveData;
private MutableLiveData<Bitmap> eventLogo;

public AboutFragmentViewModel() {
Expand Down Expand Up @@ -91,12 +91,11 @@ private List<Object> getSessionsList(List<Session> bookmarked) {
return sessionsList;
}

public LiveData<List<Speaker>> getFeaturedSpeakers() {
if (featuredSpeakers == null) {
LiveRealmData<Speaker> featuredSpeakersLiveData = RealmDataRepository.asLiveData(realmRepo.getFeaturedSpeakers());
featuredSpeakers = Transformations.map(featuredSpeakersLiveData, input -> input);
public LiveRealmData<Speaker> getFeaturedSpeakers() {
if (featuredSpeakersLiveData == null) {
featuredSpeakersLiveData = RealmDataRepository.asLiveData(realmRepo.getFeaturedSpeakers());
}
return featuredSpeakers;
return featuredSpeakersLiveData;
}

public LiveData<Bitmap> getEventLogo(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.Transformations;
import android.arch.lifecycle.ViewModel;

import org.fossasia.openevent.common.api.APIClient;
import org.fossasia.openevent.common.arch.LiveRealmData;
import org.fossasia.openevent.data.DiscountCode;
import org.fossasia.openevent.data.repository.RealmDataRepository;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;

public class DiscountFragmentViewModel extends ViewModel {

private LiveData<List<DiscountCode>> discountCodes;
private LiveRealmData<DiscountCode> discountCodeLiveRealmData;
private RealmDataRepository realmRepo;
private MutableLiveData<Boolean> discountCodesDownloadResponse;
private CompositeDisposable compositeDisposable;
Expand All @@ -30,12 +27,11 @@ public DiscountFragmentViewModel() {
}


public LiveData<List<DiscountCode>> getDiscountCodes() {
if (discountCodes == null) {
LiveRealmData<DiscountCode> discountCodeLiveRealmData = RealmDataRepository.asLiveData(realmRepo.getDiscountCodes());
discountCodes = Transformations.map(discountCodeLiveRealmData, input -> input);
public LiveRealmData<DiscountCode> getDiscountCodes() {
if (discountCodeLiveRealmData == null) {
discountCodeLiveRealmData = RealmDataRepository.asLiveData(realmRepo.getDiscountCodes());
}
return discountCodes;
return discountCodeLiveRealmData;
}

public LiveData<Boolean> downloadDiscountCodes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.Transformations;
import android.arch.lifecycle.ViewModel;

import org.fossasia.openevent.common.api.APIClient;
import org.fossasia.openevent.common.arch.LiveRealmData;
import org.fossasia.openevent.data.FAQ;
import org.fossasia.openevent.data.repository.RealmDataRepository;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
Expand All @@ -20,7 +17,7 @@
public class FAQViewModel extends ViewModel {

private RealmDataRepository realmRepo;
private LiveData<List<FAQ>> faqData;
private LiveRealmData<FAQ> faqLiveRealmData;
private MutableLiveData<Boolean> faqOnDownloadResponse;
private final CompositeDisposable compositeDisposable;

Expand All @@ -29,12 +26,11 @@ public FAQViewModel() {
compositeDisposable = new CompositeDisposable();
}

public LiveData<List<FAQ>> getFaqData() {
if (faqData == null) {
LiveRealmData<FAQ> faqLiveRealmData = RealmDataRepository.asLiveData(realmRepo.getEventFAQs());
faqData = Transformations.map(faqLiveRealmData, input -> input);
public LiveRealmData<FAQ> getFaqData() {
if (faqLiveRealmData == null) {
faqLiveRealmData = RealmDataRepository.asLiveData(realmRepo.getEventFAQs());
}
return faqData;
return faqLiveRealmData;
}

public LiveData<Boolean> downloadFAQ() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.Transformations;
import android.arch.lifecycle.ViewModel;

import org.fossasia.openevent.common.arch.LiveRealmData;
Expand All @@ -19,7 +18,7 @@
public class NotificationsFragmentViewModel extends ViewModel {

private RealmDataRepository realmRepo;
private LiveData<List<Notification>> notificationsData;
private LiveRealmData<Notification> liveNotificationsRealmData;
private MutableLiveData<Boolean> notificationDownloadResponse;
private final CompositeDisposable compositeDisposable;
private final NotificationsRepository notificationsRepository;
Expand All @@ -30,12 +29,11 @@ public NotificationsFragmentViewModel() {
notificationsRepository = new NotificationsRepository();
}

public LiveData<List<Notification>> getNotificationsData() {
if (notificationsData == null) {
LiveRealmData<Notification> liveRealmData = RealmDataRepository.asLiveData(realmRepo.getNotifications());
notificationsData = Transformations.map(liveRealmData, input -> input);
public LiveRealmData<Notification> getNotificationsData() {
if (liveNotificationsRealmData == null) {
liveNotificationsRealmData = RealmDataRepository.asLiveData(realmRepo.getNotifications());
}
return notificationsData;
return liveNotificationsRealmData;
}

public LiveData<Boolean> downloadNotifications() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
package org.fossasia.openevent.core.sponsor;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Transformations;
import android.arch.lifecycle.ViewModel;

import org.fossasia.openevent.data.Sponsor;
import org.fossasia.openevent.common.arch.LiveRealmData;
import org.fossasia.openevent.data.Sponsor;
import org.fossasia.openevent.data.repository.RealmDataRepository;

import java.util.List;

public class SponsorsFragmentViewModel extends ViewModel {

private LiveData<List<Sponsor>> sponsorsList;
private LiveRealmData<Sponsor> sponsorLiveRealmData;
private RealmDataRepository realmRepo;

public SponsorsFragmentViewModel() {
realmRepo = RealmDataRepository.getDefaultInstance();
}

public LiveData<List<Sponsor>> getSponsors() {
if (sponsorsList == null) {
LiveRealmData<Sponsor> sponsorLiveRealmData = RealmDataRepository.asLiveData(realmRepo.getSponsors());
sponsorsList = Transformations.map(sponsorLiveRealmData, input -> input);
public LiveRealmData<Sponsor> getSponsors() {
if (sponsorLiveRealmData == null) {
sponsorLiveRealmData = RealmDataRepository.asLiveData(realmRepo.getSponsors());
}
return sponsorsList;
return sponsorLiveRealmData;
}

}

0 comments on commit 1f2ca18

Please sign in to comment.