android.arch.lifecycle.MutableLiveData Java Examples

The following examples show how to use android.arch.lifecycle.MutableLiveData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AssignmentViewModel.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
public LiveData<Resource<Assignment>> saveAssignment(
        @NonNull Assignment assignment, String name, @Nullable Attachment attachment) {
    MutableLiveData<Resource<Assignment>> result = new MutableLiveData<>();
    new ResourceAsyncTask<>(result, () -> {
        if (attachment != null) {
            attachment.setModelCode(assignment.getCode());
            attachment.setModelType(ModelType.ASSIGNMENT);
            AttachmentsStore.getInstance().saveModel(attachment);
        }

        assignment.setName(name);

        AssignmentsStore.getInstance().saveModel(assignment);

        return Resource.success(assignment);
    }).execute();
    return result;
}
 
Example #2
Source File: AssignmentRepository.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
public LiveData<Resource<List<Assignment>>> updateOrders(List<Assignment> assignments) {
    MutableLiveData<Resource<List<Assignment>>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () -> {
        ((AssignmentsStore) getStore()).updateOrders(assignments);
        return assignments;
    }).execute();
    return result;
}
 
Example #3
Source File: BindApp1Preferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an LiveData to <code>valueSet</code> property
 *
 * @return
 * an LiveData to <code>valueSet</code> property
 */
public MutableLiveData<HashSet<String>> getValueSetAsLiveData() {
  KriptonLiveDataHandlerImpl<HashSet<String>> liveData=new KriptonLiveDataHandlerImpl<HashSet<String>>() {
    @Override
    protected HashSet<String> compute() {
      BindApp1Preferences.this.refresh();
      return BindApp1Preferences.this.getValueSet();
    }
  };
  registryLiveData("value_set", liveData);
  return liveData.getLiveData();
}
 
Example #4
Source File: LoginViewModel.java    From journaldev with MIT License 5 votes vote down vote up
LiveData<User> getUser() {
    if (userMutableLiveData == null) {
        userMutableLiveData = new MutableLiveData<>();
    }

    return userMutableLiveData;
}
 
Example #5
Source File: BindApp1Preferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an LiveData to <code>right</code> property
 *
 * @return
 * an LiveData to <code>right</code> property
 */
public MutableLiveData<Integer> getRightAsLiveData() {
  KriptonLiveDataHandlerImpl<Integer> liveData=new KriptonLiveDataHandlerImpl<Integer>() {
    @Override
    protected Integer compute() {
      BindApp1Preferences.this.refresh();
      return BindApp1Preferences.this.getRight();
    }
  };
  registryLiveData("right", liveData);
  return liveData.getLiveData();
}
 
Example #6
Source File: CommunitySelectionPageViewModel.java    From 1Rramp-Android with MIT License 5 votes vote down vote up
public MutableLiveData<List<CommunityModel>> getCommunities(CommunitySelectionPageCallback communitySelectionPageCallback) {
  if (communities == null) {
    communities = new MutableLiveData<>();
    fetchCommunities();
  }
  this.communitySelectionPageCallback = communitySelectionPageCallback;
  return communities;
}
 
Example #7
Source File: BindAppPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an LiveData to <code>valueBoolean</code> property
 *
 * @return
 * an LiveData to <code>valueBoolean</code> property
 */
public MutableLiveData<Boolean> getValueBooleanAsLiveData() {
  KriptonLiveDataHandlerImpl<Boolean> liveData=new KriptonLiveDataHandlerImpl<Boolean>() {
    @Override
    protected Boolean compute() {
      BindAppPreferences.this.refresh();
      return BindAppPreferences.this.getValueBoolean();
    }
  };
  registryLiveData("value_boolean", liveData);
  return liveData.getLiveData();
}
 
Example #8
Source File: DirectoryViewModel.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public LiveData<Resource<List<Directory>>> getDirectories(String itemId) {
    MutableLiveData<Resource<List<Directory>>> result = new MutableLiveData<>();
    OneDriveManager.getInstance().getItems(itemId, new ICallback<Item>() {
        @Override
        public void success(Item item) {
            if (item.children == null || item.children.getCurrentPage().isEmpty()) {
                // The folder is empty
                result.setValue(Resource.success(new LinkedList<>()));
            } else {
                // Return the children folder
                List<Directory> list = new LinkedList<>();
                LogUtils.d(item.children);
                for (final Item childItem : item.children.getCurrentPage()) {
                    if (childItem.folder == null) continue;
                    list.add(OneDriveManager.getDirectory(childItem));
                }
                result.setValue(Resource.success(list));
            }
        }

        @Override
        public void failure(ClientException ex) {
            result.setValue(Resource.error(ex.getMessage(), null));
        }
    });
    return result;
}
 
Example #9
Source File: ProjectsViewModel.java    From MVVM with MIT License 5 votes vote down vote up
public LiveData<Lcee<Projects>> getProjects() {
    if (null == ldProjects) {
        ldPage = new MutableLiveData<>();
        ldProjects = Transformations.switchMap(ldPage, new Function<Integer, LiveData<Lcee<Projects>>>() {
            @Override
            public LiveData<Lcee<Projects>> apply(Integer page) {
                return projectsRepository.getProjects(page);
            }
        });
    }
    return ldProjects;
}
 
Example #10
Source File: CompanionViewModel.java    From robocar with Apache License 2.0 5 votes vote down vote up
public CompanionViewModel(Application application) {
    super(application);
    mGoogleApiClient = NearbyConnectionManager.createNearbyApiClient(application);
    mRobocarDiscoverer = new RobocarDiscoverer(mGoogleApiClient);

    mNavigationState = new MutableLiveData<>();
    mNavigationState.setValue(NavigationState.DISCOVERY_UI);
}
 
Example #11
Source File: BindAppPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an LiveData to <code>description</code> property
 *
 * @return
 * an LiveData to <code>description</code> property
 */
public MutableLiveData<String> getDescriptionAsLiveData() {
  KriptonLiveDataHandlerImpl<String> liveData=new KriptonLiveDataHandlerImpl<String>() {
    @Override
    protected String compute() {
      BindAppPreferences.this.refresh();
      return BindAppPreferences.this.getDescription();
    }
  };
  registryLiveData("description", liveData);
  return liveData.getLiveData();
}
 
Example #12
Source File: BindAppPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an LiveData to <code>stringArray</code> property
 *
 * @return
 * an LiveData to <code>stringArray</code> property
 */
public MutableLiveData<String[]> getStringArrayAsLiveData() {
  KriptonLiveDataHandlerImpl<String[]> liveData=new KriptonLiveDataHandlerImpl<String[]>() {
    @Override
    protected String[] compute() {
      BindAppPreferences.this.refresh();
      return BindAppPreferences.this.getStringArray();
    }
  };
  registryLiveData("string_array", liveData);
  return liveData.getLiveData();
}
 
Example #13
Source File: BindAppPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an LiveData to <code>valueBoolean</code> property
 *
 * @return
 * an LiveData to <code>valueBoolean</code> property
 */
public MutableLiveData<Boolean> getValueBooleanAsLiveData() {
  KriptonLiveDataHandlerImpl<Boolean> liveData=new KriptonLiveDataHandlerImpl<Boolean>() {
    @Override
    protected Boolean compute() {
      BindAppPreferences.this.refresh();
      return BindAppPreferences.this.getValueBoolean();
    }
  };
  registryLiveData("value_boolean", liveData);
  return liveData.getLiveData();
}
 
Example #14
Source File: BaseRepository.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public LiveData<Resource<T>> update(T model) {
    MutableLiveData<Resource<T>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () -> {
        getStore().update(model);
        return model;
    }).execute();
    return result;
}
 
Example #15
Source File: BaseRepository.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public LiveData<Resource<T>> update(T model, Status toStatus) {
    MutableLiveData<Resource<T>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () -> {
        getStore().update(model, toStatus);
        return model;
    }).execute();
    return result;
}
 
Example #16
Source File: BaseRepository.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public LiveData<Resource<T>> saveOrUpdate(T model) {
    MutableLiveData<Resource<T>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () -> {
        getStore().saveOrUpdate(model);
        return model;
    }).execute();
    return result;
}
 
Example #17
Source File: ShareLocationViewModel.java    From Track-My-Location with GNU General Public License v3.0 5 votes vote down vote up
@Inject
public ShareLocationViewModel(Application application,
                              DeviceLocationDataStore deviceLocationDataStore) {
    super(application);
    mDeviceLocationDataStore = deviceLocationDataStore;
    mSharingState = new MutableLiveData<>();
}
 
Example #18
Source File: EarthquakeViewModel.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
public LiveData<List<Earthquake>> getEarthquakes() {
  if (earthquakes == null) {
    earthquakes = new MutableLiveData<List<Earthquake>>();
    loadEarthquakes();
  }
  return earthquakes;
}
 
Example #19
Source File: AssignmentRepository.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public LiveData<Resource<List<Assignment>>> getAssignments(
        long startMillis, long endMillis, boolean includeCompleted) {
    MutableLiveData<Resource<List<Assignment>>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () ->
            ((AssignmentsStore) getStore()).getAssignments(startMillis, endMillis,
                    (includeCompleted ? "" : AssignmentSchema.TABLE_NAME + "." + AssignmentSchema.PROGRESS + " != 100 "))
    ).execute();
    return result;
}
 
Example #20
Source File: AssignmentRepository.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get all assignments to display fot today fragment: overdue assignments and those start today.
 *
 * @return the assignments */
public LiveData<Resource<List<Assignment>>> getToday() {
    MutableLiveData<Resource<List<Assignment>>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () -> {
        long todayEnd = TimeUtils.endToday().getTime();
        return getStore().get(AssignmentSchema.START_TIME + " <= " + todayEnd +
                " AND " + AssignmentSchema.PROGRESS + " != " + Constants.MAX_ASSIGNMENT_PROGRESS,
                AssignmentSchema.START_TIME + " DESC, " + AssignmentSchema.NOTICE_TIME, Status.NORMAL, false);
    }).execute();
    return result;
}
 
Example #21
Source File: UserViewModel.java    From MVVM with MIT License 5 votes vote down vote up
public LiveData<Lcee<User>> getUser() {
    if (null == ldUser) {
        ldUsername = new MutableLiveData<>();
        ldUser = Transformations.switchMap(ldUsername, new Function<String, LiveData<Lcee<User>>>() {
            @Override
            public LiveData<Lcee<User>> apply(String username) {
                return userRepository.getUser(username);
            }
        });
    }
    return ldUser;
}
 
Example #22
Source File: PermissionLiveData.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@MainThread
public static MutableLiveData<Boolean> get() {
    if (sPermissionLiveData == null) {
        sPermissionLiveData = new MutableLiveData<>() ;
    }
    return sPermissionLiveData;
}
 
Example #23
Source File: CategoryRepository.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public LiveData<Resource<Category>> update(Category category, Status fromStatus, Status toStatus) {
    MutableLiveData<Resource<Category>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () -> {
        ((CategoryStore) getStore()).update(category, fromStatus, toStatus);
        return category;
    }).execute();
    return result;
}
 
Example #24
Source File: BindAppPreferences.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an LiveData to <code>name</code> property
 *
 * @return
 * an LiveData to <code>name</code> property
 */
public MutableLiveData<String> getNameAsLiveData() {
  KriptonLiveDataHandlerImpl<String> liveData=new KriptonLiveDataHandlerImpl<String>() {
    @Override
    protected String compute() {
      BindAppPreferences.this.refresh();
      return BindAppPreferences.this.getName();
    }
  };
  registryLiveData("name", liveData);
  return liveData.getLiveData();
}
 
Example #25
Source File: AttachmentRepository.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public LiveData<Resource<Attachment>> saveIfNew(Attachment attachment) {
    MutableLiveData<Resource<Attachment>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () -> {
        if (getStore().isNewModel(attachment.getCode())) {
            getStore().saveModel(attachment);
        }
        return attachment;
    }).execute();
    return result;
}
 
Example #26
Source File: AttachmentRepository.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public LiveData<Resource<List<Attachment>>> updateAttachments(Assignment assignment, List<Attachment> attachments) {
    MutableLiveData<Resource<List<Attachment>>> result = new MutableLiveData<>();
    new NormalAsyncTask<>(result, () -> {
        ((AttachmentsStore) getStore()).updateAttachments(assignment, attachments);
        return attachments;
    }).execute();
    return result;
}
 
Example #27
Source File: UserViewModel.java    From MVVM with MIT License 5 votes vote down vote up
public LiveData<Lcee<User>> getUser() {
    if (null == ldUser) {
        ldUsername = new MutableLiveData<>();
        ldUser = Transformations.switchMap(ldUsername, new Function<String, LiveData<Lcee<User>>>() {
            @Override
            public LiveData<Lcee<User>> apply(String username) {
                return userRepository.getUser(username);
            }
        });
    }
    return ldUser;
}
 
Example #28
Source File: BlockUrlProvidersViewModel.java    From notSABS with MIT License 5 votes vote down vote up
public LiveData<List<BlockUrlProvider>> getBlockUrlProviders() {
    if (blockUrlProviders == null) {
        blockUrlProviders = new MutableLiveData<>();
        loadBlockUrlProviders();
    }
    return blockUrlProviders;
}
 
Example #29
Source File: ProfileViewModel.java    From notSABS with MIT License 5 votes vote down vote up
public LiveData<PolicyPackage> getPolicyPackagesLiveData() {
    if (policyPackagesLiveData == null) {
        policyPackagesLiveData = new MutableLiveData<>();
        loadPolicyPackages();
    }
    return policyPackagesLiveData;
}
 
Example #30
Source File: BillingModel.java    From notSABS with MIT License 5 votes vote down vote up
public BillingModel() {
    isSupportedLiveData = new MutableLiveData<>();
    isPremiumLiveData = new MutableLiveData<>();
    priceLiveData = new MutableLiveData<>();
    threeMonthPriceLiveData = new MutableLiveData<>();
    isSupportedLiveData.postValue(false);
    isPremiumLiveData.postValue(false);
    priceLiveData.postValue("");
}