Commit 76d0e27e authored by Robert Hitt's avatar Robert Hitt
Browse files

Fixed crashes on rotation

parent 0aecabaa
Pipeline #745 passed with stages
in 4 minutes and 46 seconds
......@@ -17,6 +17,7 @@ import butterknife.ButterKnife;
import fr.castorflex.android.circularprogressbar.CircularProgressBar;
import io.realm.Realm;
import srct.whatsopen.R;
import srct.whatsopen.ui.MainView;
import srct.whatsopen.ui.presenters.MainPresenter;
......@@ -25,7 +26,6 @@ import srct.whatsopen.ui.adapters.FacilityListFragmentPagerAdapter;
public class MainActivity extends AppCompatActivity implements MainView {
@BindView(R.id.progress_bar) CircularProgressBar mProgressBar;
@BindView(R.id.list_view) LinearLayout mListView;
private MainPresenter mPresenter;
......@@ -34,14 +34,16 @@ public class MainActivity extends AppCompatActivity implements MainView {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Bind them views
ButterKnife.bind(this);
// Set up presenter
mPresenter = new MainPresenter();
mPresenter.attachView(this);
// Get facility data
mPresenter.loadFacilities();
// Get facility data if necessary
if(Realm.getDefaultInstance().isEmpty())
mPresenter.loadFacilities();
// Configure toolbar
Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
......
......@@ -28,9 +28,11 @@ import srct.whatsopen.ui.activities.MainActivity;
public class MainPresenter {
private MainActivity mMainView;
private SharedPreferences pref;
public void attachView(MainActivity view) {
this.mMainView = view;
pref = PreferenceManager.getDefaultSharedPreferences(mMainView);
}
public void detachView() {
......@@ -53,11 +55,13 @@ public class MainPresenter {
.subscribe(new Subscriber<List<Facility>>() {
@Override
public void onCompleted() {
mMainView.dismissProgressBar();
if(mMainView != null)
mMainView.dismissProgressBar();
}
@Override
public void onError(Throwable e) {
mMainView.dismissProgressBar();
if(mMainView != null)
mMainView.dismissProgressBar();
// should probably show some error message
}
@Override
......@@ -69,7 +73,6 @@ public class MainPresenter {
// Sets the favorite and open status of each Facility
private List<Facility> setStatus(List<Facility> facilities) {
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mMainView);
for(Facility facility : facilities) {
// Query SharedReferences for each Facility's favorite status. defaults to false
......@@ -87,7 +90,6 @@ public class MainPresenter {
realm.close();
}
// Uses the device time to determine which facilities should be open
public boolean getOpenStatus(Facility facility, Calendar now) {
RealmList<OpenTimes> openTimesList = facility.getMainSchedule().getOpenTimesList();
......
......@@ -38,6 +38,7 @@
<fr.castorflex.android.circularprogressbar.CircularProgressBar
android:id="@+id/progress_bar"
android:indeterminate="true"
android:visibility="gone"
android:layout_gravity="center"
app:cpb_color="@color/colorPrimary"
app:cpb_rotation_speed="1.0"
......
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