Commit 41f19287 authored by Robert Hitt's avatar Robert Hitt
Browse files

Fixed bug where everything showed up as closed

parent bac38b9e
...@@ -54,7 +54,7 @@ public class MainPresenter { ...@@ -54,7 +54,7 @@ public class MainPresenter {
Observable<List<Facility>> call = service.facilityList(); Observable<List<Facility>> call = service.facilityList();
call.subscribeOn(Schedulers.io()) call.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.map(facilities1 -> setFavoriteStatus(facilities1)) .map(facilities1 -> setStatus(facilities1))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.subscribe(new Subscriber<List<Facility>>() { .subscribe(new Subscriber<List<Facility>>() {
@Override @Override
...@@ -64,6 +64,7 @@ public class MainPresenter { ...@@ -64,6 +64,7 @@ public class MainPresenter {
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
updateOpenStatus();
if(mMainView != null) if(mMainView != null)
mMainView.dismissProgressBar(); mMainView.dismissProgressBar();
Toast.makeText(mMainView.getContext(), "Error getting data; " + Toast.makeText(mMainView.getContext(), "Error getting data; " +
...@@ -77,11 +78,12 @@ public class MainPresenter { ...@@ -77,11 +78,12 @@ public class MainPresenter {
} }
// Sets the favorite and open status of each Facility // Sets the favorite and open status of each Facility
private List<Facility> setFavoriteStatus(List<Facility> facilities) { private List<Facility> setStatus(List<Facility> facilities) {
for(Facility facility : facilities) { for(Facility facility : facilities) {
// Query SharedReferences for each Facility's favorite status. defaults to false // Query SharedReferences for each Facility's favorite status. defaults to false
facility.setFavorited(pref.getBoolean(facility.getName()+"FavoriteStatus", false)); facility.setFavorited(pref.getBoolean(facility.getName()+"FavoriteStatus", false));
facility.setOpen(getOpenStatus(facility, Calendar.getInstance()));
} }
return facilities; return facilities;
...@@ -95,7 +97,7 @@ public class MainPresenter { ...@@ -95,7 +97,7 @@ public class MainPresenter {
} }
// Sets the open status of each facility in the Realm instance // Sets the open status of each facility in the Realm instance
public void updateOpenStatus() { private void updateOpenStatus() {
Realm realm = Realm.getDefaultInstance(); Realm realm = Realm.getDefaultInstance();
realm.executeTransactionAsync(bgRealm -> { realm.executeTransactionAsync(bgRealm -> {
List<Facility> facilities = bgRealm.where(Facility.class).findAll(); List<Facility> facilities = bgRealm.where(Facility.class).findAll();
......
...@@ -45,7 +45,6 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -45,7 +45,6 @@ public class MainActivity extends AppCompatActivity implements MainView {
// Reload facility data // Reload facility data
mPresenter.loadFacilities(); mPresenter.loadFacilities();
mPresenter.updateOpenStatus();
// Configure toolbar // Configure toolbar
Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar); Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment